题意:
据说就是找桥;
思路:
无敌RE......是cmp写挫了...现在数组开太大了
模板题;
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int mod=1e9+7; const int N=1e5+10; struct node{ int to; int next; }; node edge[N*4]; int tol,head[N*4]; int n; int dfn[N],low[N],tp; struct asd{ int u,v; }; asd ans[N*4]; int ans_num; bool cmp(asd x,asd y) { if(x.u<y.u) return 1; if(x.u==y.u) return x.v<y.v; return 0; } void tarjan(int u,int from) { dfn[u]=low[u]=tp++; for(int v=head[u];v!=-1;v=edge[v].next) { int to=edge[v].to; if(!dfn[to]) { tarjan(to,u); low[u]=min(low[u],low[to]); if(dfn[u]<low[to]) { ans[ans_num].u=u; ans[ans_num].v=to; if(u>to) swap(ans[ans_num].u,ans[ans_num].v); ans_num++; } } else if(to!=from) low[u]=min(low[u],dfn[to]); } } void add(int u,int v) { edge[tol].to=v; edge[tol].next=head[u]; head[u]=tol++; } void init() { tol=0; memset(head,-1,sizeof(head)); memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); ans_num=0; tp=1; } void input() { int u,v; int num; scanf("%d",&n); init(); for(int i=0;i<n;i++) { scanf("%d (%d)",&u,&num); while(num--) { scanf("%d",&v); add(u,v); } } } void solve() { for(int i=0;i<n;i++) { if(!dfn[i]) tarjan(i,-1); } } int main() { int T,cas=1; scanf("%d",&T); while(T--) { input(); solve(); printf("Case %d: ",cas++); printf("%d critical links ",ans_num); if(ans_num) sort(ans,ans+ans_num,cmp); for(int i=0; i<ans_num; i++) { printf("%d - %d ",ans[i].u,ans[i].v); } } return 0; }