这个题很简单,但是输入有毒,用字符串的我一直RE
然后换成这样瞬间AC
#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include <vector> #include <stack> using namespace std; typedef long long LL; const int N = 1e4+5; int head[N],tot,n,cnt; struct Edge{ int u,v,next; bool operator<(const Edge& rhs)const{ if(u!=rhs.u)return u<rhs.u; return v<rhs.v; } }edge[N*10],o[N*10]; void add(int u,int v){ edge[tot].v=v; edge[tot].next=head[u]; head[u]=tot++; } int dfn[N],low[N],clk; void targin(int u,int f){ dfn[u]=low[u]=++clk; for(int i=head[u];~i;i=edge[i].next){ int v=edge[i].v; if(v==f)continue; if(!dfn[v]){ targin(v,u); low[u]=min(low[u],low[v]); if(dfn[u]<low[v]){ ++cnt; o[cnt].u=min(u,v); o[cnt].v=max(u,v); } } else if(dfn[v]<low[u])low[u]=dfn[v]; } } int main(){ while(~scanf("%d",&n)){ memset(head,-1,sizeof(head)); cnt=clk=tot=0; for(int i=1;i<=n;++i){ int u,k; scanf("%d (%d)",&u,&k); while(k--){int v;scanf("%d",&v);add(u,v);} } memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); for(int i=0;i<n;++i) if(!dfn[i])targin(i,-1); printf("%d critical links ",cnt); if(cnt)sort(o+1,o+1+cnt); for(int i=1;i<=cnt;++i){ printf("%d - %d ",o[i].u,o[i].v); } printf(" "); } return 0; }