#include "stations.h"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Node{
vector<int> to;
}point[1005];
vector<int> labels;
int num;
void build(int now,int last,int p){
if(p%2==0)labels[now]=num++;
for(int i=0;i<point[now].to.size();i++){
int next=point[now].to[i];
if(next!=last)build(next,now,p+1);
}
if(p%2==1)labels[now]=num++;
}
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();}
for(int i=0;i<n-1;i++){
point[u[i]].to.push_back(v[i]);
point[v[i]].to.push_back(u[i]);
}
build(0,-1,0);
//for(int i=0;i<n;i++)cout<<i<<":"<<labels[i]<<" ";cout<<endl;
return labels;
}
int find_next_station(int s, int t, vector<int> c){
if(c.size()==1)return c[0];
if(s>c[0]){
if(t<c[1] || t>s)return c[0];
else return *upper_bound(c.begin(),c.end(),t);
}
else{
if(t<s || c[c.size()-2])return c[c.size()-1];
else return *lower_bound(c.begin(),c.end(),t);
}
}
Compilation message
stations.cpp: In function 'void build(int, int, int)':
stations.cpp:16:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for(int i=0;i<point[now].to.size();i++){
| ~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
528 ms |
620 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
524 ms |
656 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
516 ms |
528 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
884 ms |
400 KB |
Output is correct |
2 |
Incorrect |
644 ms |
508 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
552 ms |
616 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |