Submission #1089030

#TimeUsernameProblemLanguageResultExecution timeMemory
1089030urd05Toy Train (IOI17_train)C++17
0 / 100
7 ms3164 KiB
#include "train.h" #include <bits/stdc++.h> using namespace std; vector<int> adj[5005]; vector<int> rev[5005]; int n,m; int deg[5005]; bool vis[5005]; bool chk[5005];//true면 A편편 int dp[5005]; int aa[5005]; int ans(int v) { if (dp[v]!=-1) { return dp[v]; } if (!vis[v]) { return dp[v]=chk[v]; } if (aa[v]==0) { int ret=1; for(int nt:adj[v]) { if (ans(nt)==0) { ret=0; break; } } return dp[v]=ret; } if (aa[v]==1) { int ret=0; for(int nt:adj[v]) { if (ans(nt)==1) { ret=1; break; } } return dp[v]=ret; } } std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) { n=a.size(); m=u.size(); for(int i=0;i<n;i++) { aa[i]=a[i]; } for(int i=0;i<m;i++) { adj[u[i]].push_back(v[i]); rev[v[i]].push_back(u[i]); deg[v[i]]++; } queue<int> q; for(int i=0;i<n;i++) { if (deg[i]==0) { q.push(i); } } while (!q.empty()) { int now=q.front(); q.pop(); vis[now]=true; for(int nt:adj[now]) { deg[nt]--; if (deg[nt]==0) { q.push(nt); } } } for(int i=0;i<n;i++) { deg[i]=0; if (!vis[i]) { for(int nt:adj[i]) { if (!vis[nt]) { deg[i]++; } } } } for(int i=0;i<n;i++) { if (!vis[i]&&r[i]) { q.push(i); chk[i]=true; } } while (!q.empty()) { int now=q.front(); q.pop(); for(int nt:rev[now]) { if (chk[nt]||vis[nt]) { continue; } if (a[nt]==1) { chk[nt]=true; q.push(nt); } else { deg[nt]--; if (deg[nt]==0) { chk[nt]=true; q.push(nt); } } } } vector<int> ret(n); for(int i=0;i<n;i++) { ret[i]=-1; } for(int i=0;i<n;i++) { if (!vis[i]&&!chk[i]) { q.push(i); } } for(int i=0;i<n;i++) { deg[i]=0; if (!vis[i]) { for(int nt:adj[i]) { if (!vis[nt]) { deg[i]++; } } } } while (!q.empty()) { int now=q.front(); q.pop(); for(int nt:rev[now]) { if (!chk[nt]||vis[nt]) { continue; } if (a[nt]==0) { chk[nt]=false; q.push(nt); } else { deg[nt]--; if (deg[nt]==0) { chk[nt]=false; q.push(nt); } } } } memset(dp,-1,sizeof(dp)); for(int i=0;i<n;i++) { assert(!vis[i]); ret[i]=ans(i); } return ret; }

Compilation message (stderr)

train.cpp: In function 'int ans(int)':
train.cpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
   41 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...