ZOJ Problem Set - 2475 Benny's Compiler
Chieh
posted @ 2015年8月19日 18:37
in NO Answer No Speak
, 375 阅读
/* Author:Chieh Because Of Coding */ #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #define LL long long #define INF 1e9 #define EPS 1e-9 using namespace std; const int maxn=123; //bool isC[maxn][maxn]; vector<int> V[maxn]; int n,E; void init(){ for(int i=1;i<=100;i++)V[i].clear(); int u,v; // memset(isC,0,sizeof(isC)); for(int i=1;i<=n;i++){ scanf("%d%d",&u,&v); if(u==v)continue; V[u].push_back(v); // isC[u][v]=1; } /*for(int k=1;k<=100;k++){ for(int i=1;i<=100;i++){ for(int j=1;j<=100;j++){ if(isC[i][k]&&isC[k][j])isC[i][j]=1; } } }*/ scanf("%d",&E); } bool flag; bool vis[maxn]; void DFS(int now){ if(flag)return; for(int i=0;i<V[now].size();i++){ int v=V[now][i]; if(vis[v]){ flag=1; return; } vis[v]=1; DFS(v); vis[v]=0; } } void play(){ flag=0; memset(vis,0,sizeof(vis)); vis[E]=0; DFS(E); if(flag)printf("No\n"); else printf("Yes\n"); } int main() { while(scanf("%d",&n)!=EOF){ if(n<0)break; init(); play(); } // cout << "Hello world!" << endl; return 0; }