Submission #1054943

#TimeUsernameProblemLanguageResultExecution timeMemory
1054943WansurToy Train (IOI17_train)C++17
12 / 100
5 ms1628 KiB
#include <bits/stdc++.h> #include "train.h" #define ent '\n' #define f first #define s second //#define int long long using namespace std; typedef long long ll; const int maxn = 5e3 + 12; const int mod = 1e9 + 7; vector<int> g[maxn], rg[maxn]; int in[maxn], out[maxn]; bool won[maxn]; int n, m; vector<int> who_wins(vector<int> a, vector<int> r, vector<int> U, vector<int> V){ n = a.size(), m = U.size(); int v = -1; for(int i=0;i<n;i++){ if(r[i]){ assert(v == -1); v = i; } } assert(v != -1); won[v] = 1; for(int i=0;i<m;i++){ g[U[i]].push_back(V[i]); rg[V[i]].push_back(U[i]); out[U[i]]++, in[V[i]]++; } queue<int> q; q.push(v); while(q.size()){ int v = q.front(); q.pop(); for(int to:rg[v]){ if(a[to] == 1 && !won[to]){ won[to] = 1; q.push(to); } else if(a[to] == 0){ out[to]--; if(!out[to]){ won[to] = 1; q.push(to); } } } } bool ok = 1 - a[v]; for(int to:g[v]){ if(!a[v]) ok &= won[to]; else ok |= won[to]; } vector<int> ans(n); if(ok){ for(int i=0;i<n;i++){ ans[i] = won[i]; } } return ans; }
#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...