제출 #309710

#제출 시각아이디문제언어결과실행 시간메모리
309710kris01Stations (IOI20_stations)C++14
0 / 100
3040 ms2097156 KiB
#include "stations.h" #include <bits/stdc++.h> #define pii pair <int,int> #define mp make_pair using namespace std; vector < vector <int> > Adj; // Adjacency List for the graph vector <int> Tin,Tout; // Entry and Exit times respectively vector <int> Depth; // Depth of a given node from the root (node 1) int timer = 0; void DFS(int v,int p) { Tin[v] = timer++; for (int x : Adj[v]) { if (x == p) continue; Depth[x] = Depth[v] + 1; DFS(x,v); } Tout[v] = timer++; } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { std::vector<int> labels(n); Adj.resize(n); Tin.resize(n); Tout.resize(n); Depth.resize(n+1,0); for (int i = 0;i < n-1;i++) { int a = u[i]; int b = v[i]; Adj[a].push_back(b); Adj[b].push_back(a); } timer = 0; DFS(0,-1); vector <pair <int,int> > LBLS(n); // Dummy vector to sort the labels for (int i = 0;i < n;i++) { if (Depth[i] % 2 == 0) { LBLS[i] = mp(Tin[i],i); } else { LBLS[i] = mp(Tout[i],i); } } sort(LBLS.begin(),LBLS.end()); for (int i = 0;i < n;i++) { labels[LBLS[i].second] = i; } return labels; } int find_next_station(int s, int t, std::vector<int> c) { sort(c.begin(),c.end()); if (s < c[0]) { auto it = lower_bound(c.begin(),c.end(),t); if (c.size() == 1 || it == c.end()) { return c.back(); } return *it; } else { auto it = upper_bound(c.begin(),c.end(),t); if (c.size() == 1 || t > s) { return c[0]; } it--; return *it; } }
#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...