Submission #1051493

#TimeUsernameProblemLanguageResultExecution timeMemory
1051493aykhnStations (IOI20_stations)C++17
100 / 100
565 ms1288 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; const int MXN = 1e3 + 5; int in[MXN], out[MXN], tim = -1; vector<int> adj[MXN]; vector<int> labels; void dfs(int a, int p, int w) { in[a] = ++tim; for (int v : adj[a]) { if (v == p) continue; dfs(v, a, w ^ 1); } out[a] = ++tim; if (w) labels[a] = in[a]; else labels[a] = out[a]; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { tim = -1; for (int i = 0; i < n; i++) { in[i] = out[i] = 0; adj[i].clear(); } for (int i = 0; i < n - 1; i++) adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]); labels.assign(n, 0); dfs(0, 0, 0); vector<array<int, 2>> v1; for (int i = 0; i < labels.size(); i++) v1.push_back({labels[i], i}); sort(v1.begin(), v1.end()); for (int i = 0; i < v1.size(); i++) labels[v1[i][1]] = i; return labels; } int find_next_station(int s, int t, vector<int> c) { for (int x : c) if (x == t) return t; int sz = c.size(); if (sz == 1) return c[0]; else if (s < c[0]) { if (!(s <= t && t <= c[sz - 2])) return c[sz - 1]; c.pop_back(); for (int x : c) if (t <= x) return x; } else { if (!(c[1] <= t && t <= s)) return c[0]; c.erase(c.begin()); reverse(c.begin(), c.end()); for (int x : c) if (x <= t) return x; } }

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for (int i = 0; i < labels.size(); i++) v1.push_back({labels[i], i});
      |                  ~~^~~~~~~~~~~~~~~
stations.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for (int i = 0; i < v1.size(); i++) labels[v1[i][1]] = i;
      |                  ~~^~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:61:1: warning: control reaches end of non-void function [-Wreturn-type]
   61 | }
      | ^
#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...