Submission #1055022

#TimeUsernameProblemLanguageResultExecution timeMemory
1055022WansurToy Train (IOI17_train)C++17
100 / 100
168 ms1756 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]; bool won[maxn], del[maxn]; int out[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(); vector<int> ans(n); for(int i=0;i<m;i++){ g[U[i]].push_back(V[i]); rg[V[i]].push_back(U[i]); } bool ok = 0; while(true){ for(int i=0;i<n;i++){ out[i] = g[i].size(); won[i] = 0; } queue<int> q; for(int i=0;i<n;i++){ won[i] = 0; if(r[i] == 1){ won[i] = 1; q.push(i); } } while(q.size()){ int v = q.front(); q.pop(); for(int to:rg[v]){ if(a[to] && !won[to]){ won[to] = 1; q.push(to); } if(!a[to] && !won[to]){ out[to]--; if(out[to] == 0){ won[to] = 1; q.push(to); } } } } bool fg = 1; for(int i=0;i<n;i++){ if(r[i]){ bool ok = 1 - a[i]; for(int to:g[i]){ if(a[i]) ok |= won[to]; else ok &= won[to]; } fg &= ok; if(!ok) { r[i] = 0; } } } if(fg){ for(int i=0;i<n;i++){ ans[i] |= won[i]; } break; } } return ans; }

Compilation message (stderr)

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:27:10: warning: unused variable 'ok' [-Wunused-variable]
   27 |     bool ok = 0;
      |          ^~
#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...