#include "Encoder.h"
#include <vector>
#include <cstdio>
#define PB push_back
#define X first
#define Y second
using namespace std;
typedef long long ll;
const int N = 3e5 + 500;
vector < int > v[N];
ll tko[N];
void dfs(int x, int lst,int dulj){
int lg = 1, cnt = 0;
for(;(1 << lg) < (int)v[x].size() - (x != lst);lg++);
for(int y : v[x]){
if(y == lst) continue;
tko[y] = tko[x] + (1LL << dulj) * (cnt++);
dfs(y, x, dulj + lg);
}
//printf("x = %d tko = %lld dulj = %d\n", x, tko[x] + (1 << dulj), dulj);
Code(x, tko[x] + (1LL << dulj));
}
void Encode(int n, int u1[], int u2[]){
for(int i = 0;i + 1 < n;i++)
v[u1[i]].PB(u2[i]),
v[u2[i]].PB(u1[i]);
dfs(0, 0, 0);
}
#include "Device.h"
#include <cstdio>
typedef long long ll;
void InitDevice(){
return;
}
bool dijete(ll A, ll B){
int dulj_A = 0, dulj_B = 0;
for(;(1LL << dulj_A) <= A;dulj_A++);
for(;(1LL << dulj_B) <= B;dulj_B++);
if(dulj_A > dulj_B) return 0;
//printf("dulj_A = %d dulj_B = %d\n", dulj_A, dulj_B);
//printf("Je li B %lld dijete od A %lld\n", B, A);
for(int i = 0;i + 1 < dulj_A;i++){
if((A & (1 << i)) != (B & (1 << i)))
return 0;
}
//printf("DA\n");
return 1;
}
int Answer(ll A, ll B)
{
if(dijete(B, A))
return 0;
if(dijete(A, B))
return 1;
return 2;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
14848 KB |
Output is correct |
2 |
Correct |
13 ms |
14848 KB |
Output is correct |
3 |
Correct |
13 ms |
14848 KB |
Output is correct |
4 |
Correct |
13 ms |
14848 KB |
Output is correct |
5 |
Correct |
12 ms |
14848 KB |
Output is correct |
6 |
Correct |
13 ms |
14848 KB |
Output is correct |
7 |
Correct |
12 ms |
14848 KB |
Output is correct |
8 |
Correct |
13 ms |
14848 KB |
Output is correct |
9 |
Correct |
12 ms |
14848 KB |
Output is correct |
10 |
Correct |
12 ms |
14848 KB |
Output is correct |
11 |
Correct |
12 ms |
14848 KB |
Output is correct |
12 |
Correct |
12 ms |
14848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
244 ms |
28912 KB |
Output is correct - L = 6986048 |
2 |
Partially correct |
241 ms |
28912 KB |
Output is partially correct - L = 1645962072 |
3 |
Correct |
245 ms |
28912 KB |
Output is correct - L = 9021024 |
4 |
Correct |
234 ms |
28912 KB |
Output is correct - L = 1022 |
5 |
Incorrect |
187 ms |
49648 KB |
Wrong Answer [3] |
6 |
Halted |
0 ms |
0 KB |
- |