Submission #828280

#TimeUsernameProblemLanguageResultExecution timeMemory
828280tomrukStations (IOI20_stations)C++17
100 / 100
633 ms824 KiB
#include "stations.h" #include <bits/stdc++.h> #define N 1005 using namespace std; int tin[N],tout[N]; int d[N]; vector<int> adj[N]; int timer = 0; void dfs(int v,int par){ tin[v] = timer++; for(auto u:adj[v]){ if(u == par) continue; d[u] = d[v] + 1; dfs(u,v); } tout[v] = timer++; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { for(int i = 0;i<n;i++){ adj[i].clear(); } timer = 0; for(int i = 0;i<n-1;i++){ adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } dfs(0,-1); vector<int> ret(n,0); vector<int> compress; for(int i = 0;i<n;i++){ if(d[i] & 1) ret[i] = tin[i]; else ret[i] = tout[i]; compress.push_back(ret[i]); } sort(compress.begin(),compress.end()); for(int i = 0;i<n;i++){ ret[i] = lower_bound(compress.begin(),compress.end(),ret[i]) - compress.begin(); } return ret; } int find_next_station(int s, int t, vector<int> c){ if(c.size() == 1) return c[0]; if(c[0] > s){ int l = s; int r = c[c.size()-2]; if(t < l || t > r) return c.back(); int x = 1e9; for(int i = 0;i<c.size()-1;i++){ if(c[i] >= t) x = min(x,c[i]); } return x; } else{ int l = c[1]; int r = s; if(t < l || t > r) return c[0]; int x = 0; for(int i = 1;i<c.size();i++){ if(c[i] <= t) x = max(x,c[i]); } return x; } }

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int i = 0;i<c.size()-1;i++){
      |                 ~^~~~~~~~~~~
stations.cpp:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int i = 1;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...