이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int timer;
vector<bool> f;
vector<int> l, d;
vector<vector<int> > g;
void dfs(int id, bool flag = 1){
d[id] = timer++;
f[id] = flag;
for(int v : g[id]) if(d[v] == -1) dfs(v, !flag);
l[id] = timer++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
f.resize(n);
l.assign(n, -1);
d.assign(n, -1);
g.assign(n, {});
for(int i = 0; i < n - 1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
timer = 0;
dfs(0);
vector<int> ret(n);
for(int i = 0; i < n; i++){
ret[i] = (f[i] ? d[i] / 2 : l[i] / 2);
}
return ret;
}
int find_next_station(int s, int t, vector<int> c){
if(s < c[0]){
//c has leaving times
if(t < s || t > c.back()) return c.back();
return c[(int)(lower_bound(c.begin(), c.end(), t) - c.begin())];
}
else{
//c has discovery times
if(t < c.front() || t > s) return c.front();
return c[(int)(upper_bound(c.begin(), c.end(), t) - c.begin()) - 1];
}
}
/*
void test(vector<int> ll, vector<int> u, vector<int> v, int id, int t){
vector<int> c;
int n = v.size() + 1;
for(int i = 0; i < n - 1; i++){
if(u[i] == id) c.push_back(ll[v[i]]);
if(v[i] == id) c.push_back(ll[u[i]]);
}
int got = find_next_station(ll[id], ll[t], c);
sort(c.begin(), c.end());
cout << "got: " << got << endl;
cout << (int)(find(ll.begin(), ll.end(), got) - ll.begin()) << endl;
}
int main(){
vector<int> v = {0, 0, 0, 1, 1, 4}, u = {1, 4, 6, 2, 3, 5};
vector<int> labels = label(7, 10, u, v);
test(labels, u, v, 0, 5);
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |