Submission #483328

#TimeUsernameProblemLanguageResultExecution timeMemory
483328lukaszgnieckiStations (IOI20_stations)C++17
100 / 100
892 ms740 KiB
#include "stations.h" #include <bits/stdc++.h> #define ll long long #define str string #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define vc vector<char> #define vvc vector<vc> #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vvvvi vector<vvvi> #define vll vector<ll> #define vvll vector<vll> #define vvvll vector<vvll> #define vvvvll vector<vvvll> #define vs vector<str> #define vvs vector<vs> #define vpii vector<pii> #define vvpii vector<vpii> #define vpll vector<pll> #define vvpll vector<vpll> #define vb vector<bool> #define vvb vector<vb> #define rep(i, a, b) for (int i = (a); i < int(b); i++) #define repi(i, a, b) for (int i = (a); i <= int(b); i++) using namespace std; int find_next_station(int s, int t, vi neib) { if (neib.size() == 1) return neib[0]; if (s < neib[0]) { int prev = s; for (int x : neib) { if (t > prev && t <= x) { return x; } prev = x; } return neib.back(); } else { int prev = s; for (int i = neib.size() - 1; i >= 0; i--) { int x = neib[i]; if (t < prev && t >= x) { return x; } prev = x; } return neib[0]; } } void dfs_label(vvi & tr, int x, int p, int lvl, vi & lab, int & mx) { if (lvl & 1) { for (int y : tr[x]) { if (y != p) { dfs_label(tr, y, x, lvl + 1, lab, mx); } } lab[x] = mx + 1; mx = lab[x]; } else { lab[x] = mx + 1; mx = lab[x]; for (int y : tr[x]) { if (y != p) { dfs_label(tr, y, x, lvl + 1, lab, mx); } } } } vi label(int n, int k, vi u, vi v) { vvi tr(n); rep(i, 0, n - 1) { tr[u[i]].push_back(v[i]); tr[v[i]].push_back(u[i]); } vi lab(n, -1); int mx = -1; dfs_label(tr, 0, 0, 0, lab, mx); return lab; } /* int main() { vi lab = label(5, 10, {0, 1, 1, 2}, {1, 2, 3, 4}); rep(i, 0, 5) { cout << lab[i] << " "; } cout << endl; */ /*cout << 0 << " " << 4 << " " << find_next_station(0, 4, {4}) << '\n'; cout << 3 << " " << 2 << " " << find_next_station(3, 2, {4})<< '\n'; cout << 3 << " " << 0 << " " << find_next_station(3, 0, {4})<< '\n'; cout << 4 << " " << 0 << " " << find_next_station(4, 0, {0, 1, 3})<< '\n'; cout << 4 << " " << 2 << " " << find_next_station(4, 2, {0, 1, 3})<< '\n'; cout << 4 << " " << 3 << " " << find_next_station(4, 3, {0, 1, 3})<< '\n';*//* lab = label(2, 1, {0}, {1}); for (int x : lab) cout << x << " "; cout << endl; lab = label(4, 3, {0, 0, 0}, {1, 2, 3}); for (int x : lab) cout << x << " "; cout << endl; }*/
#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...