#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
vector<int>adj[1005];
vector<int> labels(1005);
int sz[1005],n;
vector<int>ans;
void dfs(int node,int par=-1){
sz[node]=1;
for(int to:adj[node]){
if(to!=par){
dfs(to,node);
sz[node]+=sz[to];
}
}
}
void solve(bool flag,int node,int l,int r,int par=-1){
labels[node]=(flag?l:r);
if(flag) l++;
for(int to:adj[node]){
if(to!=par){
solve(flag^1,to,l,l+sz[to]-1,node);
l=l+sz[to];
}
}
}
vector<int> label(int N, int k, vector<int> u, vector<int> v) {
ans.clear();
n=N;
for(int i=0;i<(n-1);i++){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0);
solve(1,0,0,n-1);
for(int i=0;i<n;i++) ans.push_back(labels[i]);
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(),c.end());
if(s==0){
for(int i=0;i<c.size();i++){
if(c[i]>=t) return c[i];
}
}
if(c.back()<s){
c.push_back(s);
for(int i=1;i<(int)(c.size()-1);i++){
if(c[i]<=t && t<c[i+1]) return c[i];
}
return c[0];
}
else{
vector<int>q;
q.push_back(s);
for(int i=0;i<c.size();i++){
q.push_back(c[i]);
}
for(int i=1;i<(int)(q.size()-1);i++){
if(q[i-1]<t && t<=q[i]) return q[i];
}
return q.back();
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:44:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=0;i<c.size();i++){
| ~^~~~~~~~~
stations.cpp:58:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i=0;i<c.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1200 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3050 ms |
412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1303 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
833 ms |
520 KB |
Output is correct |
2 |
Runtime error |
1062 ms |
2097156 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2108 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |