#include "bits/stdc++.h"
using namespace std;
int dep[1001];
int timer = 0;
vector<int> adj[1001];
int in[1001],out[1001];
void dfs(int i,int pr){
dep[i] = dep[pr]+1;
if(dep[i]%2){
timer++;
}
in[i] = timer;
for(auto j:adj[i]){
if(j==pr)continue;
dfs(j,i);
}
if(dep[i]%2==0)timer++;
out[i] = timer;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
timer = 0;
for(int i = 0;i<n;i++){
adj[i].clear();
}
for(int i = 0;i<n-1;i++){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dep[0] = 1;
dfs(0,0);
vector<int> lol;
for(int i = 0;i<n;i++){
if(dep[i]%2==0){
lol.push_back(in[i]);
//cout<<in[i]<<" ";
}else{
lol.push_back(out[i]);
//cout<<out[i]<<" ";
}
}
return lol;
}
int find_next_station(int s, int t, vector<int> c){
if(c.size()==1)return c[0];
if(c[0]<s){
vector<int> na;
for(int i = 1;i<c.size();i++)na.push_back(i);
na.push_back(s);
if(t<c[1]||t>s)return c[0];
int lol = 0;
for(int i = 0;i<na.size();i++){
if(t>=na[i]){
lol = na[i];
}
}
return lol;
}else{
vector<int> na;
na.push_back(s);
for(int i = 0;i<c.size()-1;i++)na.push_back(i);
if(t>c[c.size()-2]||t<s)return c.back();
int lol = 0;
for(int i = 0;i<na.size();i++){
if(t<=na[i]){
lol = na[i];
break;
}
}
return lol;
}
}
// int main(){
// label(9,0,{0,0,1,1,3,5,6,6},{1,5,2,3,4,6,7,8});
// }
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:48:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 1;i<c.size();i++)na.push_back(i);
| ~^~~~~~~~~
stations.cpp:52:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i = 0;i<na.size();i++){
| ~^~~~~~~~~~
stations.cpp:61:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i = 0;i<c.size()-1;i++)na.push_back(i);
| ~^~~~~~~~~~~
stations.cpp:64:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i = 0;i<na.size();i++){
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
360 ms |
684 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
310 ms |
684 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
368 ms |
684 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
576 ms |
684 KB |
Output is correct |
2 |
Incorrect |
449 ms |
940 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
378 ms |
684 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |