Submission #70163

#TimeUsernameProblemLanguageResultExecution timeMemory
70163bnahmad15Toy Train (IOI17_train)C++17
0 / 100
13 ms1620 KiB
#include "train.h" #include <bits/stdc++.h> using namespace std; const int N = 5001; int n,is[N],vis[N],own[N],to[N],self[N],flag1 = 1,flag2 = 1,low[N],tim[N],cnt = 0,can[N],comp[N],cc = 0,have[N],cycle[N]; vector <int> g[N],S,g2[N]; void DFS(int u){ low[u] = tim[u] = ++cnt; vis[u] = 1; S.push_back(u); for(int i = 0;i<g[u].size();i++){ int v = g[u][i]; if(tim[v] == -1) DFS(v); if(vis[v]) low[u] = min(low[u],low[v]); } if(low[u] == tim[u]){ cc++; int tmpp = 0; while(1){ int v = S.back(); S.pop_back(); vis[v] = 0; comp[v] = cc; tmpp++; if(v == u) break; } if(tmpp > 1) cycle[cc] = 1; } } int calc(int u){ if(can[u] != -1) return can[u]; can[u] = 0; if(cycle[u] == 1 && have[u] == 1) return can[u] = 1; for(int i = 0;i<g2[u].size();i++){ can[u] = max(can[u],calc(g2[u][i])); } return can[u]; } std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) { std::vector<int> res; n = a.size(); for(int i = 0;i<n;i++){ is[i] = self[i] = to[i] = 0,vis[i] = 0; have[i] = cycle[i] =0; } for(int i = 0;i<u.size();i++){ g[u[i]].push_back(v[i]); if(u[i] == v[i]) self[u[i]] = 1; if(u[i] + 1 == v[i]) to[u[i]] = 1; } for(int i = 0;i<n;i++) is[i] = r[i]; for(int i = 0;i<n;i++){ own[i] = a[i]; if(a[i] != 1) flag1 = 0; if(a[i] != 0) flag2 = 0; } if(flag1 == 1){ for(int i = 0;i<n;i++){ if(tim[i] == -1) DFS(i); } for(int i = 0;i<n;++i){ for(int j = 0;j<g[i].size();j++){ if(comp[i] != comp[g[i][j]]) g2[comp[i]].push_back(g[i][j]); } if(is[i]) have[comp[i]] = 1; can[i] = -1; } for(int i = 0;i<n;i++) res.push_back(calc(comp[i])); } return res; }

Compilation message (stderr)

train.cpp: In function 'void DFS(int)':
train.cpp:13:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<g[u].size();i++){
                ~^~~~~~~~~~~~
train.cpp: In function 'int calc(int)':
train.cpp:39:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<g2[u].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:52:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<u.size();i++){
                ~^~~~~~~~~
train.cpp:74: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...