1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| #include<stdio.h> #include<algorithm> #include<string.h> #include<math.h> #include<queue> #include<vector> #include<map> using namespace std; struct node { int ans,x,y,w; }; vector<int>g[200]; int vis[200][200][3]; int dp[200][200][3]; int in[200]; int cnt[200][200][3]; int main() { int T; scanf("%d",&T); for(int kase=1;kase<=T;kase++) { int n,m; scanf("%d%d",&n,&m); int x,y; for(int i=1;i<=n;i++)g[i].clear(); memset(vis,0,sizeof(vis)); memset(cnt,0,sizeof(cnt)); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=0;k<=1;k++)dp[i][j][k]=1; memset(in,0,sizeof(in)); for(int i=1;i<=m;i++) { int u,v; scanf("%d%d",&u,&v); g[v].push_back(u); in[u]++; } scanf("%d%d",&x,&y); queue<node>q; while(!q.empty())q.pop(); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=0;k<=1;k++) { if(i==j) { vis[i][j][k]=1; dp[i][j][k]=0; node temp; temp.ans=0; temp.x=temp.y=i; temp.w=k; q.push(temp); } else if(k==0 && in[i]==0) { vis[i][j][k]=1; dp[i][j][k]=0; node temp; temp.ans=0; temp.x=i; temp.y=j; temp.w=k; q.push(temp); } } while(!q.empty()) { node temp=q.front(); q.pop(); if(temp.w==0) { int l=g[temp.y].size(); for(int i=0;i<l;i++) { int v=g[temp.y][i]; if(vis[temp.x][v][1]==1)continue; dp[temp.x][v][1]=0; node temp1; temp1.x=temp.x; temp1.y=v; temp1.ans=0; temp1.w=1; q.push(temp1); vis[temp.x][v][1]=1; } } else { int l=g[temp.x].size(); for(int i=0;i<l;i++) { int v=g[temp.x][i]; if(vis[v][temp.y][0]==1)continue; cnt[v][temp.y][0]++; if(cnt[v][temp.y][0]==in[v]) { dp[v][temp.y][0]=0; node temp1; temp1.x=v; temp1.y=temp.y; temp1.ans=0; temp1.w=0; q.push(temp1); vis[v][temp.y][0]=1; } } } } if(dp[x][y][0]==1) printf("Case #%d: Yes\n",kase); else printf("Case #%d: No\n",kase); } return 0; }
|