Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么一直WA 求大神帮看看话说这题是多case吗? #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> using namespace std; int map[55][55],cnt,num; int a[55],b[55]; queue<int> que; int vis[55]; int n=0; bool flag=0; void dfs(int s){ if(flag||vis[s]==2) return ; vis[s]=2; for(int i=1;i<=n;i++){ if(map[s][i]&&vis[i]==1){ flag=1; return ; } dfs(i); } } void bfs(int del){ memset(vis,0,sizeof(vis)); vis[del]=1; while(!que.empty()) que.pop(); que.push(0); while(!que.empty()){ int u=que.front();que.pop(); vis[u]=1; for(int i=1;i<=n;i++) if(map[u][i]&&!vis[i]) que.push(i); } if(vis[n]) return ; a[cnt++]=del; flag=0; dfs(del); if(!flag) b[num++]=del; } int main(){ int s; while(scanf("%d",&s)&&s!=-1){ map[n][s]=1; int t; while(scanf("%d",&t)&&t!=-2){ map[n][t]=1; } n++; } for(int i=1;i<n;i++) bfs(i); cout<<cnt; for(int i=0;i<cnt;i++) cout<<' '<<a[i]; cout<<endl; cout<<num; for(int i=0;i<num;i++) cout<<' '<<b[i]; cout<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator