|
|
back to boardWA on test 5 I tried all test cases which were written in the discussion part and my program gives the correct answer for all of them. How to find my error: #include <bits/stdc++.h> using namespace std; #define pb push_back #define endl "\n" /*DELETE IT ON INTERACTIVES!!*/ #define mod 1000000007 #define int long long #define double long double #define all(x) x.begin(), x.end() const int N = 1e3+5; vector<int> adj[N],marked(N,0),killed(N,0),vis_1(N,0),torun(N,1),vis_2(N,0); int ok; void dfs(int node){ vis_1[node] = 1; if(killed[node]) ok = 1; for(auto go : adj[node]){ if(!vis_1[go]){ dfs(go); } } } void mark(int node){ marked[node] = 1; vis_2[node] = 1; for(auto go : adj[node]){ if(!vis_2[go]){ mark(go); } } } void solve(){
int n; cin>>n; string s,t; while(cin>>s){ if(s == "BLOOD") break; cin>>t; adj[(int)s[0] - '0'].pb((int)t[0] - '0'); torun[(int)t[0] - '0'] = 0; } int a; while(cin>>a){ killed[a] = 1; } for(int i=1;i<=n;i++){ if(torun[i]){ dfs(i); if(ok){ mark(i); } fill(all(vis_1),0); fill(all(vis_2),0); ok = 0; } } int hehe = 0; for(int i=1;i<=n;i++){ if(!marked[i]){ hehe = 1; cout<<i<<' '; } } if(!hehe) cout<<0; } int32_t main(){
cin.tie(0); ios::sync_with_stdio(0); int t=1; //cin>>t;
while(t--) solve();
return 0; } |
|
|