/**
* Author: MatijaL
* Time: 2020-09-23 18:43:46
**/
#include <stations.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pll pair<ll, ll>
#define loop(i, n) for(ll i = 0; i < n; i++)
#define FOR(i,n,m) for(ll i = n; i <= m; i++)
#define isIn(vec, item) find(vec.begin(), vec.end(), item) != vec.end()
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define inf 1000000005
#define mod 1000000007
const int limit = 1002;
vector<int> sosedi[limit];
int in[limit];
int out[limit];
int depth[limit];
int cas = 1;
map<int, int> fi;
vector<int> indeces;
//cas se incrementa za vsako povezavo v vsako smer!!
void dfs(int node, int prev, int dpt){
in[node] = cas;
depth[node] = dpt;
for(auto sosed : sosedi[node]){
if(sosed != prev){
cas++;
dfs(sosed, node, dpt+1);
}
}
cas++;
out[node] = cas;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
loop(i, n-1){
int a = u[i];
int b = v[i];
sosedi[a].pb(b);
sosedi[b].pb(a);
}
dfs(0, 0, 0);
loop(i, n){
if(depth[i] % 2 == 0){
indeces.pb(in[i]);
fi[in[i]] = i;
}else{
indeces.pb(out[i]);
fi[out[i]] = i;
}
}
//compression
sort(all(indeces));
vector<int> ans(n);
int i = 0;
for(auto index : indeces){
int node = fi[index];
ans[node] = i;
i++;
}
return ans;
}
int find_next_station(int cur, int goal, vector<int> adjacent){
if(cur == goal) return cur;
for(auto e : adjacent) if(e == goal) return e;
int mn = inf;
int mx = -1;
for(auto e : adjacent){
mn = min(mn, e);
mx = max(mx, e);
}
//ugotovi depth
int depth;
if(adjacent[0] > cur) depth = 0;
else depth = 1;
sort(all(adjacent));
if(depth == 0){
if(cur == 0){
return *upper_bound(all(adjacent), goal);
}
//cur je in poddrevesa
//parent je mx
if(goal < cur) return mx;
else return *upper_bound(all(adjacent), goal);
}
else{
//cur je out poddrevesa
int parent = mn;
if(adjacent.size() == 1) return parent;
int minChild = adjacent[1];
if(goal < minChild) return parent;
return *(upper_bound(all(adjacent), goal) - 1);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1827 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
1016 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1573 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
991 ms |
868 KB |
Output is correct |
2 |
Runtime error |
1301 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2531 ms |
2097152 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |