# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
926800 | velislavgarkov | Stations (IOI20_stations) | C++14 | 1 ms | 544 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 <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAXN=1e3+10;
struct Number {
int x;
int ind;
bool friend operator < (Number a, Number b) {
return a.x<b.x;
}
};
Number num[MAXN];
vector <int> ver[MAXN];
vector <int> ans;
int in[MAXN], out[MAXN], dep[MAXN];
int br;
void dfs(int x, int par) {
in[x]=br;
br++;
for (auto i:ver[x]) {
if (i==par) continue;
dep[i]=dep[x]+1;
dfs(i,x);
}
out[x]=br;
br++;
if (dep[x]%2==0) num[x].x=in[x];
else num[x].x=out[x];
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for (int i=0;i<n;i++) {
if (!ver[i].empty()) ver[i].clear();
num[i].ind=i;
}
for (int i=0;i<n-1;i++) {
ver[u[i]].push_back(v[i]);
ver[v[i]].push_back(u[i]);
}
dep[0]=br=0;
dfs(0,-1);
sort(num,num+n);
ans.resize(n);
for (int i=0;i<n;i++) ans[num[i].ind]=i;
for (int i=0;i<n;i++) cout << ans[i] << ' ';
cout << endl;
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
if (s==0) {
for (int i=0;i<c.size();i++) {
if (c[i]>=t) return c[i];
}
return c.back();
} else if (s<c[0]) {
//if (t<s) return c.back();
for (int i=0;i<c.size()-1;i++) {
if (c[i]>=t) return c[i];
}
return c.back();
} else {
if (t>s) return c[0];
int res=c[0];
for (int i=1;i<c.size();i++) {
if (c[i]<=t) res=c[i];
}
return res;
}
}
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... |