#include <bits/stdc++.h>
#include "stations.h"
#define pii pair<int,int>
#define in first
#define out second
#define mp make_pair
using namespace std;
vector<int> label(int n ,int k , vector<int> u , vector<int> v){
vector<int> ans(n) ;
vector<int> adj[n] ;
for(int i=0;i<n-1;i++) {
adj[u[i]].push_back(v[i]) ;
adj[v[i]].push_back(u[i]) ;
}
int tim =0;
function<void(int,int,int)> dfs = [&](int a, int p,int num ){
ans[a]=num ;
bool flg = 0 ;
for(int&x:adj[a]){
if(x!=p) {
dfs(x,a,num*2+flg) ;
flg=1;
}
}
};
dfs(0,0,1);
return ans ;
}
vector<int> get_root_path(int x){
vector<int> a ;
while(x){
a.push_back(x) ;
x/=2 ;
}
return a ;
}
vector<int> get_path(int s , int t){
vector<int> a = get_root_path(s) , b = get_root_path(t) ;
int lca = 0 ;
for(int i=0;i<min(a.size(),b.size());i++){
if(b[i]==a[i]){
lca = i ;
continue ;
}
}
vector<int> ans ;
for(int i=a.size()-1;i>lca;i--){
ans.push_back(a[i]) ;
}
ans.push_back(a[lca]) ;
for(int i=lca+1;i<b.size();i++) ans.push_back(b[i]) ;
return ans ;
}
int find_next_station(int s ,int t, vector<int> ne){
vector<int> a= get_path(s,t) ;
return a[1] ;
}
/*int main(){
vector<int> u= {0,1,2} , v = {1,2,3} ;
vector<int> res = label(4,1000000,u,v) ;
for(int x : res) cout << x <<" " ;
cout << endl ;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(i!=j){
cout << res[i]<< " "<< res[j] << ": " << find_next_station(res[i],res[j],adj[i]) << endl ;
}
}
}
return 0 ;
}*/
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:16:6: warning: unused variable 'tim' [-Wunused-variable]
16 | int tim =0;
| ^~~
stations.cpp: In function 'std::vector<int> get_path(int, int)':
stations.cpp:43:15: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
43 | for(int i=0;i<min(a.size(),b.size());i++){
| ~^~~~~~~~~~~~~~~~~~~~~~~
stations.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int i=lca+1;i<b.size();i++) ans.push_back(b[i]) ;
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
420 KB |
Invalid labels (duplicates values). scenario=2, label=0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
545 ms |
520 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
408 KB |
Invalid labels (duplicates values). scenario=1, label=0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
953 ms |
468 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
456 KB |
Invalid labels (duplicates values). scenario=1, label=0 |
2 |
Halted |
0 ms |
0 KB |
- |