#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std ;
const int N = 1e3 + 3 ;
vector<int> labels;
vector<int> adj[N];
int st = 0 ;
void dfs(int u , int p , int l){
if(st != u)
labels[u] = l ;
else labels[u] = 0 ;
for(int i = 0 ; i < adj[u].size() ; i ++){
auto f = adj[u][i];
if(f != p){
if(u == st)dfs(f , u , 1e3 * (i + 1));
else dfs(f , u , l + 1);
}
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
labels.clear();
for(int i = 0 ; i < n ; i ++)adj[i].clear();
labels.resize(n);
// clear
for(int i = 0 ; i < n - 1 ; i ++)
adj[u[i]].push_back(v[i]) , adj[v[i]].push_back(u[i]);
for(int i = 0 ; i < n ; i ++)
if(adj[i].size() > 2)st = i ;
dfs(st , -1 , 0);
return labels;
}
int find_next_station(int s, int t,vector<int> c) {
if(s / 1e3 == t / 1e3){
if(s > t)return s - 1 ;
else return s + 1 ;
}
else if(s == 0)return (t / 1000) * 1000 ;
else return(s % 1000 == 0 ? 0 : s - 1);
return c[0];
}
Compilation message
stations.cpp: In function 'void dfs(int, int, int)':
stations.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int i = 0 ; i < adj[u].size() ; i ++){
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
296 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=2004 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
304 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1007 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
572 ms |
528 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
891 ms |
400 KB |
Output is correct |
2 |
Incorrect |
725 ms |
400 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
553 ms |
528 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |