Submission #828276

#TimeUsernameProblemLanguageResultExecution timeMemory
828276tomrukStations (IOI20_stations)C++17
76 / 100
673 ms792 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); for(int i = 0;i<n;i++){ if(d[i] & 1) ret[i] = tin[i]; else ret[i] = tout[i]; } 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:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int i = 0;i<c.size()-1;i++){
      |                 ~^~~~~~~~~~~
stations.cpp:59:18: 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 = 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...