Submission #304908

#TimeUsernameProblemLanguageResultExecution timeMemory
304908model_codeStations (IOI20_stations)C++17
100 / 100
1236 ms1520 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; vector<int> sz, labels; vector<vector<int>> E; int dfsSiz(int x, int p = -1) { sz[x] = 1; for (int y : E[x]) { if (y == p) continue; sz[x] += dfsSiz(y, x); } return sz[x]; } void dfs(int x, int s, int e, int p = -1, int h = 0) { if (h & 1) { labels[x] = e--; } else { labels[x] = s++; } for (int y : E[x]) { if (y == p) continue; dfs(y, s, s + sz[y] - 1, x, h + 1); s += sz[y]; } assert(s == e + 1); } vector<int> label(int n, int k, vector<int> u, vector<int> v) { assert(u.size() == n - 1 && v.size() == n - 1); sz = vector<int>(n); labels = vector<int>(n); E = vector<vector<int>>(n); for (int i = 0; i < n - 1; ++i) { E[u[i]].push_back(v[i]); E[v[i]].push_back(u[i]); } dfsSiz(0); dfs(0, 0, n - 1); return labels; } int find_next_station(int s, int t, vector<int> c) { vector<int> sub{s, s}; int m = c.size(); if (c[0] < s) { if (m > 1) sub[0] = c[1]; if (t < sub[0] || t > sub[1]) return c[0]; for (int i = 1; i + 1 < m; ++i) if (c[i + 1] > t) return c[i]; return c[m - 1]; } else { if (s != 0 && m > 1) sub[1] = c[m - 2]; else if (s == 0) sub[1] = c[m - 1]; if (t < sub[0] || t > sub[1]) return c[m - 1]; for (int i = 0;; ++i) if (c[i] >= t) return c[i]; } }

Compilation message (stderr)

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from stations.cpp:2:
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:28:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |  assert(u.size() == n - 1 && v.size() == n - 1);
      |         ~~~~~~~~~^~~~~~~~
stations.cpp:28:39: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |  assert(u.size() == n - 1 && v.size() == n - 1);
      |                              ~~~~~~~~~^~~~~~~~
#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...