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;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
// #define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 1100;
int find_next_station(int s, int t, vector<int> c) {
// cout << " " << s << " " << t << endl;
for(auto x : c) {
if(t == x) return x;
}
if(s == 0) {
for(int i = 0; i < c.size(); i++) {
if(t < c[i]) return c[i];
}
}
if(s < c[0]) {
//s é in
if(t < s) return c.back();
if(t > c.back()) return c.back();
for(int i = 0; i < c.size(); i++) {
if(t < c[i]) return c[i];
}
}
else {
if(t > s) return c[0];
if(t < c[0]) return c[0];
for(int i = c.size() -1; i >= 0; i--) {
if(t > c[i]) return c[i];
}
}
return -1;
}
vector<int> lab;
int timer = 0;
vector<int> g[maxn];
void dfs(int a, int col, int ant) {
if(col == 0) {
lab[a] = timer;
timer++;
}
for(auto b : g[a]) {
if(b == ant) continue;
dfs(b,col^1,a);
}
if(col == 1) {
lab[a] = timer;
timer++;
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
lab.clear();
lab.resize(n);
timer = 0;
for(int i = 0; i < n; i++) {
g[i].clear();
}
for(int i = 0; i < n-1; i++) {
g[u[i]].pb(v[i]);
g[v[i]].pb(u[i]);
}
dfs(0,0,0);
// for(int i = 0; i < n; i++) cout << i << " " << lab[i] << endl;
return lab;
}
// int32_t main() {
// ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// // freopen("out.out", "w", stdout);
// int tt = 1;
// cin >> tt;
// while(tt--) {
// int n, k; cin >> n >> k;
// vector<int> u,v;
// for(int i = 0; i < n-1; i++) {
// int a,b; cin >> a >> b;
// u.pb(a);
// v.pb(b);
// }
// label(n,k,u,v);
// int q; cin >> q;
// while(q--) {
// int s, t, ans;
// cin >> s >> t >> ans;
// vector<int> v;
// for(auto b : g[s]) {
// v.pb(lab[b]);
// }
// sort(all(v));
// cout << " " << lab[ans] << " =" << find_next_station(lab[s],lab[t],v) << endl;
// }
// }
// }
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:25:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0; i < c.size(); i++) {
| ~~^~~~~~~~~~
stations.cpp:34:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i = 0; i < c.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... |