# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
658368 | jiahng | Stations (IOI20_stations) | C++14 | 0 ms | 0 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 <vector>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 200010
#define INF (ll)1e9
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
vi labels;
int co = 0;
vi adj[maxn];
void dfs(int x,int p, bool f){
if (f) labels[x] = co++;
aFOR(i, adj[x]) if (i != p) dfs(i,x,!f);
if (!f) labels[x] = co++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
FOR(i,0,n-1) adj[i].clear();
co = 0;
FOR(i,0,n-2){
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
labels = vi(n, 0);
dfs(0,-1,1);
/*
cout << "LABELS: ";
aFOR(i, labels) cout << i << ' ';
cout << '\n';
*/
return labels;
}