Submission #319712

#TimeUsernameProblemLanguageResultExecution timeMemory
319712alextodoranStations (IOI20_stations)C++17
100 / 100
1075 ms1248 KiB
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> #include "stations.h" using namespace std; const int N_MAX = 1002; vector <int> edges[N_MAX]; int sub[N_MAX]; void dfs (int u, int parent = -1) { sub[u] = 1; for(int v : edges[u]) if(v != parent) { dfs(v, u); sub[u] += sub[v]; } } int lb[N_MAX]; void solve (int u, int l, int r, bool type, int parent = -1) { if(type == 0) lb[u] = l++; else lb[u] = r--; for(int v : edges[u]) if(v != parent) { solve(v, l, l + sub[v] - 1, !type, u); l += sub[v]; } } vector <int> label (int n, int k, vector <int> u, vector <int> v) { for(int i = 1; i < n; i++) { int a = u[i - 1] + 1; int b = v[i - 1] + 1; edges[a].push_back(b); edges[b].push_back(a); } dfs(1); solve(1, 1, n, 0); vector <int> labels(n); for(int i = 1; i <= n; i++) labels[i - 1] = lb[i] - 1; for(int i = 1; i <= n; i++) edges[i].clear(); return labels; } int find_next_station (int s, int t, vector <int> c) { bool type = 1; for(int u : c) type &= (u < s); if(type == 0) { sort(c.begin(), c.end()); int root = c.back(); c.pop_back(); int l = s + 1; for(int u : c) { if(l <= t && t <= u) return u; l = u + 1; } return root; } else { sort(c.begin(), c.end()); reverse(c.begin(), c.end()); int root = c.back(); c.pop_back(); int r = s - 1; for(int u : c) { if(u <= t && t <= r) return u; r = u - 1; } return root; } }

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:61:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   61 |     for(int i = 1; i <= n; i++)
      |     ^~~
stations.cpp:63:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   63 |  return labels;
      |  ^~~~~~
#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...