Submission #311948

#TimeUsernameProblemLanguageResultExecution timeMemory
311948Eric_hooStations (IOI20_stations)C++14
100 / 100
1041 ms1160 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; vector <int> id; int TOT; vector <int> from[1010]; void dfs(int x, int last, int dep) { if (dep & 1) { id[x] = TOT++; for (int i = 0; i < from[x].size(); i++) { int v = from[x][i]; if (v == last) continue; dfs(v, x, dep + 1); } } else { for (int i = 0; i < from[x].size(); i++) { int v = from[x][i]; if (v == last) continue; dfs(v, x, dep + 1); } id[x] = TOT++; } } vector <int> label(int n, int k, vector <int> X, vector <int> Y) { for (int i = 0; i < n; i++) { from[i].clear(); } for (int i = 0; i < n - 1; i++) { from[X[i]].push_back(Y[i]); from[Y[i]].push_back(X[i]); } id.resize(n), TOT = 0, dfs(0, 0, 1); return id; } int find_next_station(int s, int t, std::vector<int> c) { if (s < c[0]) { int lst = s; for (int i = 0; i + 1 < c.size(); i++) { if (t > lst && t <= c[i]) return c[i]; } return c.back(); } int lst = s; for (int i = (int)c.size() - 1; i >= 1; i--) { if (t < lst && t >= c[i]) return c[i]; } return c[0]; }

Compilation message (stderr)

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