Submission #434453

#TimeUsernameProblemLanguageResultExecution timeMemory
434453arayiStations (IOI20_stations)C++17
100 / 100
1051 ms784 KiB
#include "stations.h" #include <iostream> #include <algorithm> #include <vector> #define ad push_back using namespace std; const int N = 1010; int n; vector<int> g[N], l; vector<pair<int, int> > a; int xr[N], ti; void dfs(int v, int par) { ti++; if(xr[v]%2==0) a.ad({ti,v}); for(auto p : g[v]) { if(p==par) continue; xr[p]=1+xr[v]; dfs(p,v); } ti++; if(xr[v]%2==1) a.ad({ti, v}); } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { ::n=n; l.clear(), a.clear(); for (int i = 0; i < n; i++) g[i].clear(),xr[i]=0; ti=0; l.resize(n); for (int i = 0; i < n - 1; i++) { g[u[i]].ad(v[i]); g[v[i]].ad(u[i]); } dfs(0, 0); sort(a.begin(), a.end()); for (int i = 0; i < a.size(); i++) l[a[i].second] = i; return l; } int find_next_station(int s, int t, std::vector<int> c) { if(c.size() == 1) return c[0]; sort(c.begin(), c.end()); if(s < c[0]) { int nx = s; for(auto p : c) { if(t > nx && t <= p) return p; nx = p; } return c.back(); } else { int nx = c[1]; for (int i = 2; i < c.size(); i++) { if(t >= nx && t < c[i]) return nx; nx = c[i]; } if(t >= nx && t < s) return nx; return c[0]; } }

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for (int i = 0; i < a.size(); i++) l[a[i].second] = i;
      |                  ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for (int i = 2; i < c.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...