Submission #306171

#TimeUsernameProblemLanguageResultExecution timeMemory
306171aljasdlasStations (IOI20_stations)C++14
100 / 100
1081 ms1280 KiB
#include "stations.h" #include <vector> #include <bits/stdc++.h> using namespace std; vector<vector<int>> AdjList; vector<int> labels; int curLabel; void dfs(int u, int p, int d) { if(d%2==0) labels[u] = curLabel++; for(auto v: AdjList[u]) { if(v != p) dfs(v, u, d+1); } if(d%2) labels[u] = curLabel++; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { // n = 10; // u.resize(n); // v.resize(n); AdjList.assign(n, vector<int>(0)); labels.assign(n,-1); curLabel = 0; for(int i = 0; i < n-1; i++) { AdjList[u[i]].push_back(v[i]); AdjList[v[i]].push_back(u[i]); } dfs(0, -1, 0); return labels; } int find_next_station(int s, int t, vector<int> c) { sort(c.begin(), c.end()); for(auto x: c) if(x == t) return x; if(c.size() == 0) return c[0]; if(s < c[0]) { if(t < s) return c.back(); for(int i = 0; i < c.size()-1; i++) if(t < c[i]) return c[i]; return c.back(); } else { if(t > s) return c[0]; for(int i = c.size()-1; i > 0; i--) if(t > c[i]) return c[i]; return c[0]; } }

Compilation message (stderr)

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