#include "Encoder.h"
#include<iostream>
#include<vector>
using namespace std;
using ll=long long;
using vl=vector<ll>;
const int Mx = 250000;
ll t=0;
vl ad[Mx];
pair<ll,ll>dfs(ll u,ll p){
if(u!=0&&ad[u].size()==1){
ll p=t;
Code(u,(t<<18)+t);
t++;
return {t-1,t-1};
}
ll l=Mx,r=0;
for(auto i:ad[u]){
if(i!=p){
auto rt=dfs(i,u);
l=min(l,rt.first);
r=max(r,rt.second);
}
}
Code(u,(l<<18)+r);
return {l,r};
}
void Encode(int N, int A[], int B[]){
for(int i=0;i<N-1;i++)
ad[A[i]].push_back(B[i]),
ad[B[i]].push_back(A[i]);
dfs(0,-1);
}
#include "Device.h"
using ll=long long;
void InitDevice(){}
int Answer(long long S, long long T){
ll l1=S>>18,r1=S-(l1<<18);
ll l2=T>>18,r2=T-(l2<<18);
if(l2<=l1&&r1<=r2)return 0;
if(l1<=l2&&r2<=r1)return 1;
return 2;
}
Compilation message
Encoder.cpp: In function 'std::pair<long long int, long long int> dfs(ll, ll)':
Encoder.cpp:16:6: warning: unused variable 'p' [-Wunused-variable]
16 | ll p=t;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9244 KB |
Output is correct |
2 |
Correct |
2 ms |
9276 KB |
Output is correct |
3 |
Incorrect |
3 ms |
9500 KB |
Wrong Answer [6] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
124 ms |
23328 KB |
Wrong Answer [6] |
2 |
Halted |
0 ms |
0 KB |
- |