#include "stations.h"
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
namespace lab {
vector<vector<int>> g;
vector<int> tin, tout, d;
int timer;
void dfs(int v, int p) {
tin[v] = ++timer;
for(auto &i : g[v]) if(i != p) {
d[i] = d[v]+1;
dfs(i, v);
}
tout[v] = timer;
}
};
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
using namespace lab;
timer = -1;
tin = tout = d = vector<int>(n);
g.assign(n, vector<int>());
for(int i = 0; i+1 < n; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs(0, 0);
std::vector<int> labels(n);
for (int i = 0; i < n; i++) {
labels[i] = (d[i]&1) ? 1000 + tout[i] : tin[i];
}
return labels;
}
int rv(int a) {
return a%1000;
}
int find_next_station(int s, int t, std::vector<int> c) {
int type = s>=1000, par;
if(s) {
if(type == 0) {//tin here, tout in neighbors
par = *max_element(all(c));
c.erase(max_element(all(c)));
} else {//tout here
par = *min_element(all(c));
c.erase(min_element(all(c)));
}
} else par = -1;
if(!type) {
if(rv(t) < rv(s)) return par;
int mn = 1<<30;
for(auto &i : c) if(rv(t) <= rv(i)) mn = min(mn, i);
if(mn == 1<<30) mn = par;
return mn;
}
if(t > s) return par;
int mx = -1;
for(auto &i : c) if(rv(t) >= rv(i)) mx = max(mx, i);
if(mx == -1) mx = par;
return mx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
536 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1009 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
512 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1511 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
508 KB |
Invalid labels (duplicates values). scenario=1, label=1863 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
973 ms |
776 KB |
Output is correct |
2 |
Correct |
667 ms |
640 KB |
Output is correct |
3 |
Incorrect |
1 ms |
256 KB |
Invalid labels (duplicates values). scenario=1, label=1003 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
512 KB |
Invalid labels (duplicates values). scenario=1, label=1997 |
2 |
Halted |
0 ms |
0 KB |
- |