Submission #586618

#TimeUsernameProblemLanguageResultExecution timeMemory
586618PiejanVDCStations (IOI20_stations)C++17
52.32 / 100
845 ms776 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; vector<int>adj[1000]; vector<int>labelss; int id; int dfs(int u, int e = -1) { labelss[u] = 1000*id; id++; int sz = 0; for(auto z : adj[u]) if(z != e) { sz += dfs(z, u); } labelss[u] += sz; return sz+1; } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { for(int i = 0 ; i < n ; i++) adj[i].clear(); labelss.clear(); id = 0; for(int i = 0 ; i < n-1 ; i++) adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]); labelss.resize(n); dfs(0); return labelss; } int find_next_station(int s, int t, std::vector<int> c) { int ID = s / 1000; int SZ = s % 1000; int ID_T = t / 1000; if(ID_T < ID || ID_T > ID + SZ) return c[0]; int curr = ID; for(int i = (ID == 0 ? 0 : 1) ; i < c.size() ; i++) { curr += 1 + (c[i] % 1000); if(curr >= ID_T) return c[i]; } return -1; }

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:42:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i = (ID == 0 ? 0 : 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...