分析:
见标进(
一看 发现是
t
a
r
j
a
n
tarjan
tarjan模板题
主要是处理下字典序最小就好了 先跑
t
a
r
j
a
n
tarjan
tarjan求出最大强连通分量点数
a
n
s
ans
ans
然后从小到大 看每个强连通分量点数
=
a
n
s
=ans
=ans 就输出即可
CODE:
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e4+5;
struct node{
int to,next;
}a[N<<1];
int n,m,tot,head[N],dfn[N],low[N];
int stack[N],con[N],top,Index,size,num[N],ans=-1;
void add(int x,int y)
{
a[++tot]=(node){y,head[x]};
head[x]=tot;
}
void tarjan(int x)
{
dfn[x]=low[x]=++Index;
stack[++top]=x;
for(int i=head[x];i;i=a[i].next)
{
int qwq=a[i].to;
if(!dfn[qwq])
{
tarjan(qwq);
low[x]=min(low[x],low[qwq]);
}
else if(!con[qwq])
low[x]=min(low[x],dfn[qwq]);
}
if(low[x]==dfn[x])
{
con[x]=++size;
num[size]++;
while(stack[top]!=x)
{
num[size]++;
con[stack[top]]=size;
top--;
}
top--;
}
}
int main(){
scanf("%d%d",&n,&m);
while(m--)
{
int x,y,op;
scanf("%d%d%d",&x,&y,&op);
if(op==1)
add(x,y);
if(op==2)
add(x,y),add(y,x);
}
for(int i=1;i<=n;i++)
if(!dfn[i]) tarjan(i);
for(int i=1;i<=size;i++)
ans=max(ans,num[i]);
printf("%d\n",ans);
for(int i=1;i<=n;i++)
if(num[con[i]]==ans)
{
int x=con[i];
for(int j=i;j<=n;j++)
if(con[j]==x)
printf("%d ",j);
return 0;
}
return 0;
}