# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
432661 |
2021-06-18T12:12:48 Z |
TryMax |
Stations (IOI20_stations) |
C++17 |
|
3000 ms |
2097156 KB |
#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 = 2e5 + 10;
int sz[N], p[N], timer;
vector<int> a[N], lb;
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[v] += sz[u];
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
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 = 0; i < n; ++i)
lb[i] = cypher(p[i], sz[i]);
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 - 1)
pr = v;
p.pb(c1);
}
sort(p.begin(), p.end());
if(t1.f < s1.f || t1.f >= p.back().f + p.back().s)
return pr;
for(int i = p.size() - 1; i >= 0; --i)
if(t1.f >= p[i].f)
return cypher(p[i].f, p[i].s);
}
/*
1
5 1000000
0 1
1 2
1 3
2 4
2
2 0 1
1 3 3
9
1
3
*/
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:52:28: warning: control reaches end of non-void function [-Wreturn-type]
52 | vector<pair<int, int>> p;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1794 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3039 ms |
5104 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1316 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
955 ms |
9992 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2125 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |