Submission #1068665

#TimeUsernameProblemLanguageResultExecution timeMemory
1068665AbitoToy Train (IOI17_train)C++17
0 / 100
706 ms1760 KiB
#include "train.h" #include <bits/stdc++.h> //#define int long long #define pb push_back using namespace std; const int N=5005; int n,vis[N]; bool a[N],c[N],cyc[N],h,self[N],par[N],sz[N]; vector<int> adj[2][N],t; void dfs0(int x){ vis[x]=1; for (auto u:adj[0][x]){ if (vis[u]) continue; dfs0(u); }t.pb(x); return; } int getpar(int x){ if (par[x]==x) return x; return par[x]=getpar(par[x]); } void link(int x,int y){ x=getpar(x); y=getpar(y); if (x==y) return; if (sz[x]>sz[y]) swap(x,y); sz[y]+=sz[x]; par[x]=y; return; } void dfs1(int x,int p){ vis[x]=1; link(x,p); for (auto u:adj[1][x]) if (!vis[u]) dfs1(u,p); return; } bool getans(int s){ queue<int> q; q.push(s); vis[s]=1; bool ok=0; while (!q.empty()){ int x=q.front(); //cout<<x<<' '; q.pop(); if (c[x]){ if (sz[getpar(x)]>1) ok=1; if (self[x]==1) ok=1; } for (auto u:adj[0][x]){ if (vis[u]) continue; else{ vis[u]=1; q.push(u); } } }//cout<<endl; return ok; } std::vector<int32_t> who_wins(std::vector<int32_t> A, std::vector<int32_t> r, std::vector<int32_t> u, std::vector<int32_t> v) { n=A.size(); for (int i=1;i<=n;i++) a[i]=A[i-1],c[i]=r[i-1],par[i]=i,sz[i]=1; for (int i=0;i<u.size();i++){ adj[0][u[i]+1].pb(v[i]+1); adj[1][v[i]+1].pb(u[i]+1); if (u[i]==v[i]) self[u[i]+1]=1; } vector<int> ans(n); for (int i=1;i<=n;i++){ if (vis[i]) continue; dfs0(i); } memset(vis,0,sizeof(vis)); reverse(t.begin(),t.end()); for (auto u:t) if (!vis[u]) dfs1(u,u); memset(vis,0,sizeof(vis)); for (int i=1;i<=n;i++){ ans[i-1]=getans(i); memset(vis,0,sizeof(vis)); } return ans; }

Compilation message (stderr)

train.cpp: In function 'bool getans(int)':
train.cpp:47:21: warning: comparison of constant '1' with boolean expression is always false [-Wbool-compare]
   47 |    if (sz[getpar(x)]>1) ok=1;
      |        ~~~~~~~~~~~~~^~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:63:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  for (int i=0;i<u.size();i++){
      |               ~^~~~~~~~~
#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...