Submission #305105

#TimeUsernameProblemLanguageResultExecution timeMemory
305105Bench0310Stations (IOI20_stations)C++17
100 / 100
1166 ms1120 KiB
#include <bits/stdc++.h> #include "stations.h" using namespace std; typedef long long ll; const int N=1000; vector<int> v[N]; vector<int> depth(N,0); vector<int> tin(N,0); vector<int> tout(N,0); int tcnt=0; void dfs(int a,int p=-1) { if(p!=-1) depth[a]=depth[p]+1; tin[a]=tcnt++; for(int to:v[a]) { if(to==p) continue; dfs(to,a); } tout[a]=tcnt-1; } vector<int> label(int n,int k,vector<int> a,vector<int> b) { for(int i=0;i<n;i++) { v[i].clear(); depth[i]=tin[i]=tout[i]=0; } tcnt=0; for(int i=0;i<n-1;i++) { v[a[i]].push_back(b[i]); v[b[i]].push_back(a[i]); } dfs(0); vector<int> res(n,0); vector<array<int,3>> z(n); for(int i=0;i<n;i++) z[i]={((depth[i]%2)==0?tin[i]:tout[i]),depth[i],i}; sort(z.begin(),z.end(),[](array<int,3> x,array<int,3> y)->bool{return (x[0]<y[0]||(x[0]==y[0]&&x[1]>y[1]));}); for(int i=0;i<n;i++) res[z[i][2]]=i; return res; } int find_next_station(int s,int t,vector<int> c) { if(c.size()==1) return c[0]; if(s==0) { for(int a:c) if(t<=a) return a; } else if(s<c[0]) //tin { if(!(s<=t&&t<=c[c.size()-2])) return c.back(); for(int a:c) if(t<=a) return a; } else //tout { if(!(c[1]<=t&&t<=s)) return c[0]; reverse(c.begin(),c.end()); for(int a:c) if(a<=t) return a; } } //int main() //{ // ios::sync_with_stdio(0); // cin.tie(0); // // return 0; //}

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:66:1: warning: control reaches end of non-void function [-Wreturn-type]
   66 | }
      | ^
#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...