#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
int A[500005],k,in[500005],out[500005],don[500005],mp[500005];
vector <int> v1[500005];
void dfs(int x,int y,int z) {
k++;
in[x]=k;
don[x]=z;
for(int i=0;i<v1[x].size();i++) {
if(v1[x][i]==y) continue;
dfs(v1[x][i],x,z+1);
}
k++;
out[x]=k;
}
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-1;i++) {
cout<<u[i]<<" "<<v[i]<<endl;
v1[u[i]].push_back(v[i]);
v1[v[i]].push_back(u[i]);
}
dfs(0,-1,0);
for(int i=0;i<n;i++) {
if(don[i]%2==0) A[i]=in[i];
else A[i]=out[i];
}
sort(A,A+n);
for(int i=0;i<n;i++) {
mp[A[i]]=i;
}
for(int i=0;i<n;i++) {
if(don[i]%2==0) labels[i]=mp[in[i]];
else labels[i]=mp[out[i]];
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(s<c[0]) {
for(int i=0;i<c.size()-1;i++) {
if(i==0) {
if(s+1<=t && t<=c[i]) return c[i];
}
else if(c[i-1]+1<=t && t<=c[i]) return c[i];
}
return c[c.size()-1];
}
else {
for(int i=1;i<c.size();i++) {
if(i==c.size()-1) {
if(c[i]<=t && t<=s-1) return c[i];
}
else if(c[i]<=t && t<=c[i+1]-1) return c[i];
}
return c[0];
}
}
Compilation message
stations.cpp: In function 'void dfs(int, int, int)':
stations.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(int i=0;i<v1[x].size();i++) {
| ~^~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i=0;i<c.size()-1;i++) {
| ~^~~~~~~~~~~
stations.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i=1;i<c.size();i++) {
| ~^~~~~~~~~
stations.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | if(i==c.size()-1) {
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
12140 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
12140 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
12140 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
12140 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
12268 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |