# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
697064 | garam1732 | Stations (IOI20_stations) | C++14 | 946 ms | 916 KiB |
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 <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
vector<int> adj[1010];
int in[1010], out[1010], cnt;
void dfs(int here, int par, bool flag, vector<int>& labels) {
in[here] = cnt++;
for(int there : adj[here]) {
if(there == par) continue;
dfs(there, here, !flag, labels);
}
out[here] = cnt++;
labels[here] = (flag ? in[here] : out[here]);
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
for(int i = 0; i < n; i++) adj[i].clear();
cnt = 0;
for(int i = 0; i < u.size(); i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0, 0, 0, labels);
priority_queue<pi> pq;
for(int i = 0; i < n; i++) pq.push(pi(labels[i], i));
for(int i = n-1; i >= 0; i--) {
labels[pq.top().second] = i;
pq.pop();
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(s < c[0]) {
if(s < t && t <= c[0]) return c[0];
for(int i = 1; i < c.size(); i++) if(c[i-1] < t && t <= c[i]) return c[i];
return *c.rbegin();
}
for(int i = 2; i < c.size(); i++) if(c[i-1] <= t && t < c[i]) return c[i-1];
if(*c.rbegin() <= t && t < s) return *c.rbegin();
return c[0];
}
Compilation message (stderr)
# | 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... |