This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int st[N], ed[N], t[N], f[N], order[N], timer;
vector<int> adj[N];
void dfs(int u) {
st[u] = timer++;
if (!t[u]) f[u] = st[u];
else f[u] = ed[u];
for(int &v : adj[u]) if (!st[v]) {
t[v] = t[u] ^ 1;
dfs(v);
}
ed[u] = timer;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
timer = 0;
for(int i = 0; i < n; i++) adj[i].clear();
for(int i = 0; i < u.size(); i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(1);
for(int i = 0; i < n; i++) order[i] = i;
sort(order, order + n, [] (const int &x, const int &y) {
if (f[x] != f[y]) return f[x] < f[y];
if (t[x] == t[y]) return st[x] > st[y];
return t[x] < t[y];
});
vector<int> labels(n);
timer = 0;
for(int cur = 0; cur < n; cur++) {
int i = order[cur];
labels[i] = timer++;
}
// for(int i = 0; i < n; i++) cout << labels[i] << " "; cout << endl;
// for(int i = 0; i < n; i++) cout << st[i] << " "; cout << endl;
// for(int i = 0; i < n; i++) cout << ed[i] << " "; cout << endl;
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
// for(int &j : c) cout << j << " "; cout << endl;
if (c.size() == 1) return c.back();
if (!s) for(int &v : c) if (v >= t) return v;
if (s <= c[0]) { // st - ed
if (s <= t && t <= c.back()) {
int ret = 1e9;
for(int &v : c) if (v >= t) ret = min(ret, v);
return ret;
}
return c.back();
}
else { // ed - st
if (c[1] <= t && t <= s) {
int ret = 0;
for(int &v : c) if (v <= t) ret = max(ret, t);
return ret;
}
return c[0];
}
}
Compilation message (stderr)
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i = 0; i < u.size(); i++) {
| ~~^~~~~~~~~~
# | 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... |