#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
vector<int>adj[1005];
int sz[1005],n;
vector<int> labels(1005);
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];
}
}
// cout << node << ' ' << sz[node] << '\n';
}
void solve(int node,int recnt,int l,int r,int par=-1){
// cout << recnt << ' ' << l << ' ' << r << '\n';
bool flag=0;
labels[node]=recnt;
if(l==recnt){
l++;
flag=1;
}
else r--;
for(int to:adj[node]){
if(to!=par){
// cout << to << ' ' << l+(flag?sz[to]-1:0) << ' ' << l << ' ' << l+sz[to]-1 << '\n';
solve(to,l+(flag?sz[to]-1:0),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(0,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<(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<(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:51:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | 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=1;i<(c.size()-1);i++){
| ~^~~~~~~~~~~~~
stations.cpp:65:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i=0;i<c.size();i++){
| ~^~~~~~~~~
stations.cpp:68:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i=1;i<(q.size()-1);i++){
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1187 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
320 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 |
1267 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
324 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 |
2105 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |