#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif
#include "Joi.h"
vector<int> roads[10005],tree[10005];
ll siz[100005],pos[100005],dia,pa,pb;
bool check[10005];
void dfs(int x){
check[x] = true;
siz[x] = 1;
pos[x] = x;
for(int i:roads[x]){
if(!check[i]){
tree[x].push_back(i);
tree[i].push_back(x);
dfs(i);
if(siz[x]+siz[i]>dia){
pa = pos[x];
pb = pos[i];
dia = max(dia,siz[x]+siz[i]);
}
if(siz[i]+1>siz[x]){
siz[x] = siz[i]+1;
pos[x] = pos[i];
}
}
}
}
ll dep[100005],par[100005];
void one(int x, int p, ll d){
par[x] = p;
dep[x] = d;
for(int i:tree[x]){
if(i!=p){
one(i,x,d+1);
}
}
}
ll nextnode,xx;
void two(int x, int p){
if(nextnode<60){
if((1LL<<nextnode)&xx){
MessageBoard(x,1);
}
else{
MessageBoard(x,0);
}
nextnode++;
}
else{
MessageBoard(x,0);
}
for(int i:tree[x]){
if(i!=p){
two(i,x);
}
}
}
void Joi(int n, int m, int a[], int b[], ll x, int t){
xx = x;
for(int i=0;i<m;i++){
roads[a[i]].push_back(b[i]);
roads[b[i]].push_back(a[i]);
}
dfs(0);
if(dia>=60){
one(pa,-1,0);
for(int i=0;i<n;i++){
if((1LL<<(dep[i]%60LL))&x){
MessageBoard(i,1);
}
else{
MessageBoard(i,0);
}
}
}
else{
one(0,-1,0);
dia/=2;
if(dep[pb]>dep[pa]){
swap(pa,pb);
}
for(int i=1;i<=dia;i++){
pa = par[pa];
}
one(pa,-1,0);
two(pa,-1);
return;
}
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif
#include "Ioi.h"
map<int,bool> conn[15005];
vector<int> roads[10005],tree[10005];
ll siz[10005],pos[10005],dia,pa,pb;
bool check[10005];
void dfs(int x){
check[x] = true;
siz[x] = 1;
pos[x] = x;
for(int i:roads[x]){
if(!check[i]){
tree[x].push_back(i);
tree[i].push_back(x);
dfs(i);
if(siz[x]+siz[i]>dia){
pa = pos[x];
pb = pos[i];
dia = max(dia,siz[x]+siz[i]);
}
if(siz[i]+1>siz[x]){
siz[x] = siz[i]+1;
pos[x] = pos[i];
}
}
}
}
ll dep[10005],par[10005];
void one(int x, int p, ll d){
par[x] = p;
dep[x] = d;
for(int i:tree[x]){
if(i!=p){
one(i,x,d+1);
}
}
}
ll ans=0,typ[10005],nextnode;
void two(int x, int p){
if(nextnode<60){
typ[x] = nextnode;
nextnode++;
}
else{
typ[x] = -1;
}
for(int i:tree[x]){
if(i!=p){
two(i,x);
}
}
}
int s;
void three(int x, int p){
s++;
vector<vector<ll>> ord;
for(int i:tree[x]){
if(i!=p and typ[i]!=-1){
ord.push_back({typ[i],i});
}
}
sort(ord.begin(),ord.end(),greater<vector<ll>>());
for(vector<ll> i:ord){
if(!conn[x][i[1]]){
exit(1);
}
if(Move(i[1])){
ans += (1LL<<(typ[i[1]]));
}
three(i[1],x);
}
if(s!=60){
if(!conn[x][p]){
exit(2);
}
Move(p);
}
}
ll Ioi(int n, int m, int a[], int b[], int p, int v, int t){
for(int i=0;i<m;i++){
roads[a[i]].push_back(b[i]);
roads[b[i]].push_back(a[i]);
conn[a[i]][b[i]] = true;
conn[b[i]][a[i]] = true;
}
dfs(0);
if(dia>=60){
one(pa,-1,0);
if(dep[p]<=60){
if(p!=pa){
while(par[p]!=pa){
if(!conn[par[p]][p]){
return -2e9;
}
Move(par[p]);
p = par[p];
}
if(!conn[par[p]][p]){
return -2e9;
}
p = par[p];
if(Move(p)){
ans += (1LL<<(dep[p]%60LL));
}
}
else{
if(v){
ans += (1LL<<(dep[p]%60LL));
}
}
for(int i=1;i<=59;i++){
for(int x:tree[p]){
if(dep[x]==i){
if(!conn[x][p]){
return -2e9;
}
p = x;
if(Move(p)){
ans += (1LL<<(dep[p]%60LL));
}
break;
}
}
}
}
else{
if(v){
ans += (1LL<<(dep[p]%60LL));
}
for(int i=1;i<=59;i++){
if(!conn[par[p]][p]){
return -2e9;
}
p = par[p];
if(Move(p)){
ans += (1LL<<(dep[p]%60LL));
}
}
}
}
else{
one(0,-1,0);
dia/=2;
if(dep[pb]>dep[pa]){
swap(pa,pb);
}
for(int i=1;i<=dia;i++){
pa = par[pa];
}
one(pa,-1,0);
if(p!=pa){
while(par[p]!=pa){
if(!conn[par[p]][p]){
return -2e9;
}
Move(par[p]);
p = par[p];
}
if(!conn[par[p]][p]){
return -2e9;
}
p = par[p];
if(Move(p)){
ans += (1LL<<(0LL%60LL));
}
}
else{
if(v){
ans += (1LL<<(0LL%60LL));
}
}
two(pa,-1);
three(pa,-1);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2316 KB |
Output is correct |
2 |
Correct |
2 ms |
2308 KB |
Output is correct |
3 |
Correct |
3 ms |
2452 KB |
Output is correct |
4 |
Correct |
2 ms |
2316 KB |
Output is correct |
5 |
Correct |
2 ms |
2308 KB |
Output is correct |
6 |
Correct |
2 ms |
2316 KB |
Output is correct |
7 |
Correct |
2 ms |
2448 KB |
Output is correct |
8 |
Correct |
2 ms |
2452 KB |
Output is correct |
9 |
Correct |
2 ms |
2316 KB |
Output is correct |
10 |
Correct |
2 ms |
2316 KB |
Output is correct |
11 |
Correct |
7 ms |
3132 KB |
Output is correct |
12 |
Correct |
2 ms |
2316 KB |
Output is correct |
13 |
Correct |
2 ms |
2320 KB |
Output is correct |
14 |
Correct |
2 ms |
2448 KB |
Output is correct |
15 |
Correct |
2 ms |
2440 KB |
Output is correct |
16 |
Correct |
2 ms |
2440 KB |
Output is correct |
17 |
Correct |
2 ms |
2448 KB |
Output is correct |
18 |
Correct |
2 ms |
2440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
8604 KB |
Output is correct |
2 |
Correct |
28 ms |
8536 KB |
Output is correct |
3 |
Correct |
31 ms |
8524 KB |
Output is correct |
4 |
Correct |
19 ms |
6252 KB |
Output is correct |
5 |
Correct |
17 ms |
6708 KB |
Output is correct |
6 |
Correct |
17 ms |
6480 KB |
Output is correct |
7 |
Correct |
18 ms |
6600 KB |
Output is correct |
8 |
Correct |
17 ms |
6732 KB |
Output is correct |
9 |
Correct |
17 ms |
6712 KB |
Output is correct |
10 |
Correct |
17 ms |
6088 KB |
Output is correct |
11 |
Correct |
18 ms |
6176 KB |
Output is correct |
12 |
Correct |
15 ms |
5692 KB |
Output is correct |
13 |
Correct |
16 ms |
5624 KB |
Output is correct |
14 |
Correct |
17 ms |
5824 KB |
Output is correct |
15 |
Correct |
20 ms |
5888 KB |
Output is correct |
16 |
Correct |
18 ms |
6064 KB |
Output is correct |
17 |
Correct |
19 ms |
6072 KB |
Output is correct |
18 |
Correct |
18 ms |
6088 KB |
Output is correct |
19 |
Correct |
20 ms |
6096 KB |
Output is correct |
20 |
Correct |
16 ms |
6776 KB |
Output is correct |
21 |
Correct |
14 ms |
6644 KB |
Output is correct |
22 |
Correct |
17 ms |
6428 KB |
Output is correct |
23 |
Correct |
17 ms |
6604 KB |
Output is correct |
24 |
Correct |
18 ms |
6456 KB |
Output is correct |
25 |
Correct |
17 ms |
6516 KB |
Output is correct |
26 |
Correct |
17 ms |
6568 KB |
Output is correct |
27 |
Correct |
18 ms |
6852 KB |
Output is correct |
28 |
Correct |
19 ms |
6824 KB |
Output is correct |
29 |
Correct |
17 ms |
6376 KB |
Output is correct |
30 |
Correct |
17 ms |
6544 KB |
Output is correct |
31 |
Correct |
2 ms |
2320 KB |
Output is correct |
32 |
Correct |
3 ms |
2312 KB |
Output is correct |
33 |
Correct |
2 ms |
2452 KB |
Output is correct |
34 |
Correct |
2 ms |
2320 KB |
Output is correct |
35 |
Correct |
2 ms |
2440 KB |
Output is correct |
36 |
Correct |
2 ms |
2320 KB |
Output is correct |
37 |
Incorrect |
2 ms |
2324 KB |
Wrong Answer [7] |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2288 KB |
Output is correct |
2 |
Correct |
2 ms |
2320 KB |
Output is correct |
3 |
Correct |
2 ms |
2376 KB |
Output is correct |
4 |
Correct |
4 ms |
3256 KB |
Output is correct |
5 |
Correct |
4 ms |
3248 KB |
Output is correct |
6 |
Correct |
4 ms |
3184 KB |
Output is correct |
7 |
Correct |
4 ms |
3188 KB |
Output is correct |
8 |
Correct |
4 ms |
3108 KB |
Output is correct |
9 |
Correct |
14 ms |
7684 KB |
Output is correct |
10 |
Correct |
14 ms |
7852 KB |
Output is correct |
11 |
Correct |
13 ms |
7744 KB |
Output is correct |
12 |
Correct |
2 ms |
2316 KB |
Output is correct |
13 |
Correct |
2 ms |
2312 KB |
Output is correct |
14 |
Correct |
2 ms |
2324 KB |
Output is correct |
15 |
Correct |
2 ms |
2316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
8668 KB |
Output is correct |
2 |
Correct |
31 ms |
9052 KB |
Output is correct |
3 |
Correct |
33 ms |
9036 KB |
Output is correct |
4 |
Correct |
18 ms |
6320 KB |
Output is correct |
5 |
Correct |
17 ms |
7396 KB |
Output is correct |
6 |
Incorrect |
18 ms |
6812 KB |
Wrong Answer [7] |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
8644 KB |
Output is correct |
2 |
Correct |
31 ms |
9024 KB |
Output is correct |
3 |
Correct |
31 ms |
9112 KB |
Output is correct |
4 |
Correct |
22 ms |
6176 KB |
Output is correct |
5 |
Correct |
17 ms |
7596 KB |
Output is correct |
6 |
Correct |
18 ms |
6700 KB |
Output is correct |
7 |
Correct |
18 ms |
6608 KB |
Output is correct |
8 |
Correct |
18 ms |
6836 KB |
Output is correct |
9 |
Correct |
17 ms |
6696 KB |
Output is correct |
10 |
Correct |
18 ms |
6316 KB |
Output is correct |
11 |
Correct |
20 ms |
6316 KB |
Output is correct |
12 |
Correct |
18 ms |
5772 KB |
Output is correct |
13 |
Correct |
18 ms |
5768 KB |
Output is correct |
14 |
Correct |
19 ms |
5932 KB |
Output is correct |
15 |
Correct |
18 ms |
6040 KB |
Output is correct |
16 |
Correct |
23 ms |
6076 KB |
Output is correct |
17 |
Correct |
22 ms |
6268 KB |
Output is correct |
18 |
Correct |
19 ms |
6260 KB |
Output is correct |
19 |
Correct |
18 ms |
6320 KB |
Output is correct |
20 |
Correct |
15 ms |
6956 KB |
Output is correct |
21 |
Correct |
14 ms |
6952 KB |
Output is correct |
22 |
Correct |
18 ms |
6636 KB |
Output is correct |
23 |
Correct |
18 ms |
6656 KB |
Output is correct |
24 |
Correct |
18 ms |
6688 KB |
Output is correct |
25 |
Correct |
17 ms |
6676 KB |
Output is correct |
26 |
Correct |
18 ms |
6552 KB |
Output is correct |
27 |
Correct |
17 ms |
6964 KB |
Output is correct |
28 |
Correct |
18 ms |
6940 KB |
Output is correct |
29 |
Correct |
17 ms |
6672 KB |
Output is correct |
30 |
Correct |
17 ms |
6584 KB |
Output is correct |
31 |
Correct |
2 ms |
2320 KB |
Output is correct |
32 |
Correct |
2 ms |
2324 KB |
Output is correct |
33 |
Correct |
2 ms |
2372 KB |
Output is correct |
34 |
Correct |
2 ms |
2312 KB |
Output is correct |
35 |
Correct |
2 ms |
2316 KB |
Output is correct |
36 |
Incorrect |
2 ms |
2312 KB |
Wrong Answer [7] |
37 |
Halted |
0 ms |
0 KB |
- |