Submission #64834

#TimeUsernameProblemLanguageResultExecution timeMemory
64834mohammad_kilaniToy Train (IOI17_train)C++17
0 / 100
474 ms1684 KiB
#include "train.h" #include <bits/stdc++.h> using namespace std; const int N = 5010; vector< int > res , a , g[N] , r , g2[N]; int n , vis[N] , vi = 0 , last , out[N]; void make(int node){ for(int i=0;i<g2[node].size();i++){ if(res[g2[node][i]] != -1) continue; out[g2[node][i]]--; if(a[g2[node][i]] == a[node]){ if(res[node] == a[node]){ res[g2[node][i]] = a[node]; make(g2[node][i]); } else{ if(out[g2[node][i]] == 0){ res[g2[node][i]] = a[node] ^ 1; make(g2[node][i]); } } } else{ if(res[node] == a[node]){ if(out[g2[node][i]] == 0){ res[g2[node][i]] = a[node]; make(g2[node][i]); } } else{ res[g2[node][i]] = a[node] ^ 1; make(g2[node][i]); } } } } bool DFS(int node){ vis[node] = vi; if(a[node] == 0 && r[node]) return false; if(node == last) return true; for(int i=0;i<g[node].size();i++){ if(vis[g[node][i]] != vi && a[g[node][i]] == a[last]){ if(DFS(g[node][i])) return true; } } return false; } std::vector<int> who_wins(std::vector<int> A, std::vector<int> R, std::vector<int> u, std::vector<int> v) { a = A; n = (int)a.size(); r = R; res.resize(n , -1); for(int i = 0;i<(int)u.size();i++){ g[u[i]].push_back(v[i]); } for(int i=0;i<n;i++){ if(res[i] != -1) continue; last = i; vi++; if(a[i] == 0 || r[i]){ for(int j = 0;j<g[i].size();j++){ if(a[g[i][j]] == a[i] && vis[g[i][j]] != vi && DFS(g[i][j])){ res[i] = a[i]; break; } } } if(res[i] != -1) make(i); } for(int i=0;i<n;i++){ if(res[i] == -1) res[i] = a[i] ^ 1; } return res; }

Compilation message (stderr)

train.cpp: In function 'void make(int)':
train.cpp:10:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g2[node].size();i++){
              ~^~~~~~~~~~~~~~~~
train.cpp: In function 'bool DFS(int)':
train.cpp:46:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[node].size();i++){
              ~^~~~~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:69:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j = 0;j<g[i].size();j++){
                  ~^~~~~~~~~~~~
#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...