#include "stations.h"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Node{
vector<int> to;
int deg,in,out;
}point[1005];
vector<int> labels;
int num;
int build(int now,int p){
point[now].in=point[now].out=num++;
for(int i=0;i<point[now].to.size();i++){
int next=point[now].to[i];
point[now].out=max(point[now].out,build(next,p+1));
}
if(p%2==0)labels[now]=point[now].in;
else labels[now]=point[now].out;
return point[now].out;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
num=0;
labels.clear();labels.resize(n);
for(int i=0;i<n;i++){
point[i].to.clear();
point[i].deg=0;
point[i].in=-1;
point[i].out=-1;
}
int root=0;
for(int i=0;i<n-1;i++){
point[u[i]].to.push_back(v[i]);
point[u[i]].deg++;
if(point[u[i]].deg>point[root].deg)root=u[i];
point[v[i]].to.push_back(u[i]);
point[v[i]].deg++;
if(point[v[i]].deg>point[root].deg)root=v[i];
}
build(root,0);
//for(int i=0;i<n;i++)cout<<labels[i]<<" ";cout<<endl;
return labels;
}
int find_next_station(int s, int t, vector<int> c){
bool way=true;
for(int i=0;i<c.size();i++){
if(s<c[i]){
way=false;
break;
}
}
int ls=-1,rs=-1;
if(way){
sort(c.begin(),c.end());
ls=c[1]-1;rs=s;
if(t<ls || t>rs)return c[0];
for(int i=1;i<c.size();i++){
ls=c[i];rs=(i==c.size()-1?s:c[i+1]-1);
if(ls<=t && t<=rs)return c[i];
}
}
else{
sort(c.rbegin(),c.rend());
ls=s;rs=c[1];
if(t<ls || t>rs)return c[0];
for(int i=1;i<c.size();i++){
ls=(i==1?s+1:c[i-1]+1);rs=c[i];
if(ls<=t && t<=rs)return c[i];
}
}
}
Compilation message
stations.cpp: In function 'int build(int, int)':
stations.cpp:17:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i=0;i<point[now].to.size();i++){
| ~^~~~~~~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:55:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i=0;i<c.size();i++){
| ~^~~~~~~~~
stations.cpp:69:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i=1;i<c.size();i++){
| ~^~~~~~~~~
stations.cpp:70:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | ls=c[i];rs=(i==c.size()-1?s:c[i+1]-1);
| ~^~~~~~~~~~~~
stations.cpp:80:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int i=1;i<c.size();i++){
| ~^~~~~~~~~
stations.cpp:85:1: warning: control reaches end of non-void function [-Wreturn-type]
85 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2489 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1087 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1126 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1181 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1089 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |