/// Author: Wang, Yen-Jen
#include "Encoder.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const int MAX_N = 250000 + 7;
static int dp[MAX_N];
static ll dp2[MAX_N];
static vector<int> G[MAX_N];
static void dfs(int u , int fa) {
if(fa == -1) {
dp[u] = 0;
dp2[u] = 0;
}
assert(dp[u] <= 61);
int cc = 0;
int cnt = (int)G[u].size();
if(~fa) cnt--;
while((1<<cc) < cnt) cc++;
for(int v : G[u]) {
if(v == fa) continue;
dp[v] = dp[u] + cc + 1;
dp2[v] = ((ll)cnt<<dp[u]) | dp2[u];
cnt--;
dfs(v , u);
}
dp2[u] |= (1ll<<dp[u]);
dp[u]++;
}
void Encode(int N , int A[] , int B[]) {
for(int i = 0; i < N; i++) G[i].clear();
for(int i = 0; i < N - 1; i++) {
G[A[i]].push_back(B[i]);
G[B[i]].push_back(A[i]);
}
dfs(0 , -1);
for(int i = 0; i < N; i++) Code(i , dp2[i]);
}
/// Author: Wang, Yen-Jen
#include "Device.h"
#include <bits/stdc++.h>
using namespace std;
void InitDevice() {
}
inline static bool check(vector<int> a , vector<int> b) {
for(int i = 0; i < (int)a.size(); i++) {
if(a[i] != b[i]) return 0;
}
return 1;
}
inline static vector<int> decode(long long x) {
vector<int> v;
while(x) {
v.push_back(x&1);
x >>= 1;
}
v.pop_back();
return v;
}
int Answer(long long S , long long T) {
vector<int> a = decode(S);
vector<int> b = decode(T);
if((int)b.size() < (int)a.size() && check(b , a)) return 0;
else if((int)a.size() < (int)b.size() && check(a , b)) return 1;
else return 2;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12544 KB |
Output is correct |
2 |
Correct |
8 ms |
12544 KB |
Output is correct |
3 |
Correct |
9 ms |
12544 KB |
Output is correct |
4 |
Correct |
8 ms |
12664 KB |
Output is correct |
5 |
Correct |
9 ms |
12544 KB |
Output is correct |
6 |
Correct |
8 ms |
12544 KB |
Output is correct |
7 |
Correct |
8 ms |
12488 KB |
Output is correct |
8 |
Correct |
9 ms |
12544 KB |
Output is correct |
9 |
Correct |
8 ms |
12544 KB |
Output is correct |
10 |
Correct |
8 ms |
12544 KB |
Output is correct |
11 |
Correct |
9 ms |
12544 KB |
Output is correct |
12 |
Correct |
8 ms |
12544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
332 ms |
19456 KB |
Output is partially correct - L = 6057858364 |
2 |
Incorrect |
336 ms |
21784 KB |
Output isn't correct - L = 7314959047315 |
3 |
Halted |
0 ms |
0 KB |
- |