#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) {
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:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i=0;i<c.size();i++){
| ~^~~~~~~~~
stations.cpp:57:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i=0;i<c.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1246 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
312 KB |
Invalid length of array as the response of 'label'. scenario=1, n=994, len=1990 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1277 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
200 KB |
Invalid length of array as the response of 'label'. scenario=1, n=2, len=4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2114 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |