#include "stations.h"
#include <bits/stdc++.h>
#ifdef LOCAL
#include "stub.cpp"
#endif // LOCAL
#define f first
#define s second
#define pb push_back
using namespace std;
const int N = 2e6 + 10;
int sz[N], p[N], timer, was[N];
vector<int> a[N];
int cypher(int a, int b){
return a * 1000 + (b - 1);
}
pair<int, int> decyper(int num){
return {num / 1000, num % 1000 + 1};
}
void dfs(int u, int pr){
sz[u] = 1;
p[u] = timer++;
for(auto v : a[u])
if(pr != v){
dfs(v, u);
sz[u] += sz[v];
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> lb;
lb.resize(n);
for(int i = 0; i < n - 1; ++i){
a[u[i]].pb(v[i]);
a[v[i]].pb(u[i]);
}
dfs(0, -1);
for(int i = 1; i < n; ++i)
if(p[i] == 0)
exit(1);
for(int i = 0; i < n; ++i)
lb[i] = cypher(p[i], sz[i]);
exit(0);
return lb;
}
int find_next_station(int s, int t, vector<int> c) {
pair<int, int> s1 = decyper(s);
pair<int, int> t1 = decyper(t);
int pr = 0;
vector<pair<int, int>> p;
for(auto v : c){
pair<int, int> c1 = decyper(v);
if(c1.f <= s1.f)
pr = v;
p.pb(c1);
}
sort(p.begin(), p.end());
// cout << s1.f << " " << s1.s << endl;
// cout << t1.f << " " << t1.s << endl;
if(t1.f < s1.f || t1.f >= s1.f + s1.s)
return pr;
// cout << 1 << endl;
for(int i = p.size() - 1; i >= 0; --i)
if(t1.f >= p[i].f)
return cypher(p[i].f, p[i].s);
return cypher(p[0].f, p[0].s);
}
/*
1
7 1000000
0 1
0 2
1 3
1 4
2 5
2 6
2
2 0 1
1 3 2
9
1
3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
33 ms |
47176 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
47260 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
47176 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
47320 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
33 ms |
47248 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |