修改中……
模板:
class graph
{
private:
struct edge
{
int from,to,next;
} e[maxm];
public:
int m,n;
int first[maxn];
void addedge(int from,int to)
{
e[++m]= (edge)
{
from,to,first[from]
};
first[from]=m;
}
int dfn[maxn],low[maxn],sccno[maxn],sz[maxn];
int cl,now;
int stk[maxn],top;
void dfs(int u)
{
dfn[u]=low[u]=++cl;
stk[++top]=u;
for(int i=first[u]; i; i=e[i].next)
{
int v=e[i].to;
if(!dfn[v])
{
dfs(v);
low[u]=min(low[u],low[v]);
}
else if(!sccno[v])low[u]=min(low[u],dfn[v]);
}
if(low[u]==dfn[u])
{
now++;
while(top)
{
int v=stk[top--];
sccno[v]=now;
sz[now]++;
if(v==u)break;
}
}
}
bool out[maxn];
int work()
{
/*根据题目*/
}
void read()
{
int t,x,y;
scanf("%d%d",&n,&t);
for(int i=1; i<=t; ++i) scanf("%d%d",&x,&y),addedge(x,y);
return;
}
} g;