Submission #789651

#TimeUsernameProblemLanguageResultExecution timeMemory
789651esomerToy Train (IOI17_train)C++17
0 / 100
7 ms1296 KiB
#include<bits/stdc++.h> #include "train.h" using namespace std; typedef long long ll; void process(vector<int>& A, vector<int>& R, vector<int>& U, vector<int>& V, vector<bool>& forced, vector<int>& out, vector<vector<int>>& radj){ int n = (int)A.size(); int m = (int)U.size(); queue<int> q; for(int i = 0; i < n; i++){ if(out[i] == 0){ forced[i] = 0; q.push(i); } } vector<int> org = out; while(!q.empty()){ int x = q.front(); q.pop(); for(int node : radj[x]){ out[node]--; if(forced[node] == 0) continue; if(out[node] == 0) {q.push(node); forced[node] = 0;} if(A[node] == 1){ forced[node] = 0; q.push(node); } } } out = org; for(int i = 0; i < n; i++){ if(out[i] == 0){ q.push(i); } } while(!q.empty()){ int x = q.front(); q.pop(); for(int node : radj[x]){ out[node]--; if(forced[node] == 1) continue; if(out[node] == 0) {q.push(node); forced[node] = 1;} if(A[node] == 0){ forced[node] = 1; q.push(node); } } } out = org; } vector<int> who_wins(vector<int> A, vector<int> R, vector<int> U, vector<int> V){ int n = (int)A.size(); int m = (int)U.size(); bool stop = 0; vector<bool> forced; //If 1, then it can be forced by B into a cycle with no R's. vector<int> out(n); vector<vector<int>> radj(n); for(int i = 0; i < m; i++){ out[U[i]]++; radj[V[i]].push_back(U[i]); } while(!stop){ stop = 1; forced.assign(n, 1); process(A, R, U, V, forced, out, radj); for(int i = 0; i < n; i++){ if(forced[i] == 1 && R[i] == 1) {R[i] = 0; stop = 0;} } } vector<int> ans(n); for(int i = 0; i < n; i++){ if(forced[i] == 1) ans[i] = 0; else ans[i] = 1; } return ans; }

Compilation message (stderr)

train.cpp: In function 'void process(std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<bool>&, std::vector<int>&, std::vector<std::vector<int> >&)':
train.cpp:10:6: warning: unused variable 'm' [-Wunused-variable]
   10 |  int m = (int)U.size();
      |      ^
#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...