输入输出没整明白也是醉了==
还有 能不能细心点儿???这要是比赛因为内存开大了WA一次冤不冤??
/********** hud4324 **********/ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int M=4e6+10,N=2e3+10; int head[N],ed; char str[2006][2006]; struct node{ int to,next; }edge[M]; int sta[N],vis[N],low[N],dfn[N],top; //,out[N] void init(){ ed=0; memset(head,-1,sizeof(head)); memset(edge,0,sizeof(edge)); memset(sta,0,sizeof(sta)); } void addedge(int a,int b){ edge[ed].to=b; edge[ed].next=head[a]; head[a]=ed++; } void tarbfs(int k,int cnt,int &num){ vis[k]=1; low[k]=cnt; dfn[k]=cnt; sta[top++]=k; for(int i=head[k];i>-1;i=edge[i].next){ if(vis[edge[i].to]==0) tarbfs(edge[i].to,++cnt,num); if(vis[edge[i].to]==1) low[k]=min(low[k],low[edge[i].to]); } if(dfn[k]==low[k]){ ++num; while(top>0&&sta[top]!=k){ //printf("%d ",sta[top]); top--; low[sta[top]]=num; vis[sta[top]]=2; }// } } int tarjan(int n){ int num=0,cnt=1; top=0; memset(vis,0,sizeof(vis)); memset(low,0,sizeof(low)); for(int i=1;i<=n;i++){ if(vis[i]==0) tarbfs(i,cnt,num); } return num; } int main() { // freopen("cin.txt","r",stdin); int n,m,t,b; scanf("%d",&t); b=1; while(t--){ int a; init(); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%s",str[i]+1); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(str[i][j]=='1') addedge(i,j); /*for(int i=1;i<=ed;i++) { for(int k=head[i];k!=-1;k=edge[k].next) printf("u=%d v=%d ",i,edge[k].to); printf("\n"); }*/ int num=tarjan(n); //printf("%d ",num); printf("Case #%d: ",b++); if(num>=1&&num!=n) puts("Yes"); else puts("No"); } return 0; }