Submission #306080

#TimeUsernameProblemLanguageResultExecution timeMemory
306080eriksuenderhaufStations (IOI20_stations)C++17
100 / 100
1047 ms1280 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; vector<int> label(int n, int k, vector<int> u, vector<int> v) { vector<int> deg(n); vector<vector<int>> adj(n); for (int i = 0; i < n - 1; i++) deg[u[i]]++, deg[v[i]]++, adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]);; vector<int> labels(n); function<void(int,int)> init = [&](int u, int p) { if (~p) adj[u].erase(find(adj[u].begin(), adj[u].end(), p)); for (int v: adj[u]) init(v, u); }; init(0, -1); // function<void(int,int)> dfs; // function<void(int,int,int,int)> join = [&](int u, int l, int r, int v) { // if (l > r) return; // if (l == r) // dfs(adj[u][l], 2*v+1); // else { // int m = (l+r) / 2; // join(u, l, m, v*2+1); // join(u, m+1, r, v*2+2); // } // }; // dfs = [&](int u, int l) { // labels[u] = l; // join(u, 0, adj[u].size()-1, l); // }; int l = 0; function<void(int,int)> dfs = [&](int u, int d) { if (d == 0) labels[u] = l++; for (int v: adj[u]) dfs(v, d ^ 1); if (d == 1) labels[u] = l++; }; dfs(0, 0); return labels; } int find_next_station(int s, int t, vector<int> c) { sort(c.begin(), c.end()); for (int i: c) if (i == t) return i; if (c.size() > 1) { if (s < c[0]) { // d = 0 int l = s; for (int i = 0; i+1 < c.size(); i++) { if (l <= t && t <= c[i]) return c[i]; l = c[i]; } return c.back(); } else { // d = 1 c.push_back(s); int l = c[1]; for (int i = 2; i < c.size(); i++) { if (l <= t && t <= c[i]) return l; l = c[i]; } } } return c[0]; }

Compilation message (stderr)

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