#include "Joi.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
namespace{
const int maxn=10010;
const int logg=60;
int boja[maxn];
int bio[maxn];
int p[maxn];
vector<int> g[maxn];
vector<int> stablo[maxn];
int deg[maxn];
set<int> lisce;
int klk=0;
bool dfs(int node){
bio[node]=1;
klk++;
boja[node]=klk-1;
if(klk==60) return true;
for(int i:g[node]){
if(bio[i]) continue;
stablo[node].push_back(i);
p[i]=node;
if(dfs(i)) return true;
}
return false;
}
void dfs2(int node){
bio[node]=2;
for(int i:g[node]){
if(bio[i]==1){
p[node]=i;
p[i]=-1;
dfs2(i);
p[node]=-1;
p[i]=node;
}else if(bio[i]==0){
int uzimam=-1;
if(*lisce.begin()==node){
uzimam=*(++lisce.begin());
}else uzimam=*lisce.begin();
boja[i]=boja[uzimam];
p[node]=i;
p[i]=-1;
deg[p[uzimam]]--;
deg[uzimam]--;
lisce.erase(uzimam);
if(deg[p[uzimam]]==1) lisce.emplace(p[uzimam]);
lisce.emplace(i);
if(deg[node]==1) lisce.erase(node);
deg[node]++;
deg[i]++;
if(deg[i]==1) lisce.emplace(i);
dfs2(i);
if(deg[i]==1) lisce.erase(i);
deg[node]--;
deg[i]--;
if(deg[node]==1) lisce.emplace(node);
lisce.erase(i);
if(deg[p[uzimam]]==1) lisce.erase(p[uzimam]);
lisce.emplace(uzimam);
deg[uzimam]++;
deg[p[uzimam]]++;
p[node]=-1;
p[i]=node;
}
}
}
}
void Joi(int n, int m, int a[], int b[], ll x, int t) {
for(int i=0;i<m;i++){
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
p[0]=-1;
dfs(0);
for(int i=0;i<n;i++) if(bio[i]==1) for(int j:stablo[i]) deg[i]++,deg[j]++;
for(int i=0;i<n;i++) if(bio[i]==1 && deg[i]==1) lisce.emplace(i);
dfs2(0);
for(int i=0;i<n;i++) MessageBoard(i,((1LL<<boja[i])&x)!=0);
}
#include "Ioi.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
namespace{
const int maxn=10010;
const int logg=60;
int boja[maxn];
int bio[maxn];
int p[maxn];
vector<int> g[maxn];
vector<int> stablo[maxn];
int deg[maxn];
set<int> lisce;
int klk=0;
set<int> imam;
int poc;
ll res=0;
set<int> koristio;
bool dfs(int node){
bio[node]=1;
imam.emplace(node);
klk++;
boja[node]=klk-1;
if(klk==60) return true;
for(int i:g[node]){
if(bio[i]) continue;
stablo[node].push_back(i);
p[i]=node;
if(dfs(i)) return true;
}
return false;
}
bool dfs2(int node){
if(node==poc){
return true;
}
bio[node]=2;
for(int i:g[node]){
if(bio[i]==1){
p[node]=i;
p[i]=-1;
if(dfs2(i)) return true;
p[node]=-1;
p[i]=node;
}else if(bio[i]==0){
int uzimam=-1;
if(*lisce.begin()==node){
uzimam=*(++lisce.begin());
}else uzimam=*lisce.begin();
assert(lisce.size()>=2);
assert(uzimam!=node);
assert(p[uzimam]!=uzimam);
assert(i!=uzimam);
boja[i]=boja[uzimam];
p[node]=i;
p[i]=-1;
assert(deg[uzimam]==1);
assert(imam.find(uzimam)!=imam.end());
imam.erase(uzimam);
assert(imam.find(i)==imam.end());
assert(p[uzimam]!=i);
imam.emplace(i);
deg[p[uzimam]]--;
deg[uzimam]--;
lisce.erase(uzimam);
assert(deg[p[uzimam]]>0);
if(deg[p[uzimam]]==1) lisce.emplace(p[uzimam]);
if(deg[node]==1) lisce.erase(node);
deg[node]++;
deg[i]++;
if(deg[i]==1) lisce.emplace(i);
if(dfs2(i)) return true;
if(deg[i]==1) lisce.erase(i);
deg[i]--;
deg[node]--;
if(deg[node]==1) lisce.emplace(node);
if(deg[p[uzimam]]==1) lisce.erase(p[uzimam]);
lisce.emplace(uzimam);
deg[uzimam]++;
deg[p[uzimam]]++;
imam.erase(i);
imam.emplace(uzimam);
p[node]=-1;
p[i]=node;
}
}
return false;
}
int v;
int klk2=0;
void uradi(int node){
klk2++;
//assert(koristio.find(boja[node])==koristio.end());
koristio.emplace(boja[node]);
res+=(1ll<<boja[node])*v;
bio[node]=3;
for(int i:g[node]){
if(bio[i]==3) continue;
if(imam.find(i)==imam.end()) continue;
v=Move(i);
uradi(i);
v=Move(node);
}
}
}
ll Ioi(int n, int m, int a[], int b[], int _poc, int _v, int t){
poc=_poc;
v=_v;
for(int i=0;i<m;i++){
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
p[0]=-1;
dfs(0);
assert(imam.size()==60);
if(imam.find(poc)==imam.end()){
for(int i=0;i<n;i++) if(bio[i]==1) for(int j:stablo[i]) deg[i]++,deg[j]++;
for(int i=0;i<n;i++) if(bio[i]==1 && deg[i]==1) lisce.emplace(i);
dfs2(0);
}
assert(imam.size()==60);
uradi(poc);
assert(koristio.size()==60);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
Output is correct |
2 |
Correct |
2 ms |
1540 KB |
Output is correct |
3 |
Correct |
2 ms |
1548 KB |
Output is correct |
4 |
Correct |
2 ms |
1536 KB |
Output is correct |
5 |
Correct |
2 ms |
1536 KB |
Output is correct |
6 |
Correct |
2 ms |
1536 KB |
Output is correct |
7 |
Correct |
2 ms |
1552 KB |
Output is correct |
8 |
Correct |
2 ms |
1548 KB |
Output is correct |
9 |
Correct |
2 ms |
1548 KB |
Output is correct |
10 |
Correct |
1 ms |
1536 KB |
Output is correct |
11 |
Correct |
4 ms |
1928 KB |
Output is correct |
12 |
Correct |
0 ms |
1536 KB |
Output is correct |
13 |
Correct |
1 ms |
1548 KB |
Output is correct |
14 |
Correct |
2 ms |
1560 KB |
Output is correct |
15 |
Correct |
2 ms |
1548 KB |
Output is correct |
16 |
Correct |
2 ms |
1552 KB |
Output is correct |
17 |
Correct |
2 ms |
1540 KB |
Output is correct |
18 |
Correct |
2 ms |
1548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
5024 KB |
Output is correct |
2 |
Correct |
22 ms |
5308 KB |
Output is correct |
3 |
Correct |
20 ms |
5128 KB |
Output is correct |
4 |
Correct |
16 ms |
3272 KB |
Output is correct |
5 |
Correct |
16 ms |
4292 KB |
Output is correct |
6 |
Correct |
18 ms |
3908 KB |
Output is correct |
7 |
Correct |
14 ms |
4048 KB |
Output is correct |
8 |
Correct |
12 ms |
3788 KB |
Output is correct |
9 |
Correct |
16 ms |
4244 KB |
Output is correct |
10 |
Correct |
11 ms |
3264 KB |
Output is correct |
11 |
Correct |
12 ms |
3392 KB |
Output is correct |
12 |
Correct |
13 ms |
3208 KB |
Output is correct |
13 |
Correct |
14 ms |
3132 KB |
Output is correct |
14 |
Correct |
12 ms |
3268 KB |
Output is correct |
15 |
Correct |
15 ms |
3236 KB |
Output is correct |
16 |
Correct |
16 ms |
3268 KB |
Output is correct |
17 |
Correct |
13 ms |
3244 KB |
Output is correct |
18 |
Correct |
15 ms |
3268 KB |
Output is correct |
19 |
Correct |
15 ms |
3372 KB |
Output is correct |
20 |
Correct |
13 ms |
4424 KB |
Output is correct |
21 |
Correct |
13 ms |
4288 KB |
Output is correct |
22 |
Correct |
17 ms |
3784 KB |
Output is correct |
23 |
Correct |
16 ms |
4120 KB |
Output is correct |
24 |
Correct |
14 ms |
3784 KB |
Output is correct |
25 |
Correct |
16 ms |
4060 KB |
Output is correct |
26 |
Correct |
15 ms |
4164 KB |
Output is correct |
27 |
Correct |
13 ms |
3912 KB |
Output is correct |
28 |
Correct |
15 ms |
4180 KB |
Output is correct |
29 |
Correct |
12 ms |
3700 KB |
Output is correct |
30 |
Correct |
15 ms |
3900 KB |
Output is correct |
31 |
Correct |
2 ms |
1544 KB |
Output is correct |
32 |
Correct |
1 ms |
1532 KB |
Output is correct |
33 |
Correct |
2 ms |
1548 KB |
Output is correct |
34 |
Correct |
2 ms |
1544 KB |
Output is correct |
35 |
Correct |
1 ms |
1544 KB |
Output is correct |
36 |
Correct |
1 ms |
1588 KB |
Output is correct |
37 |
Correct |
2 ms |
1536 KB |
Output is correct |
38 |
Correct |
2 ms |
1536 KB |
Output is correct |
39 |
Correct |
2 ms |
1544 KB |
Output is correct |
40 |
Correct |
2 ms |
1544 KB |
Output is correct |
41 |
Correct |
2 ms |
1544 KB |
Output is correct |
42 |
Correct |
1 ms |
1544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1536 KB |
Output is correct |
2 |
Correct |
2 ms |
1540 KB |
Output is correct |
3 |
Correct |
1 ms |
1532 KB |
Output is correct |
4 |
Correct |
3 ms |
2084 KB |
Output is correct |
5 |
Correct |
3 ms |
2076 KB |
Output is correct |
6 |
Correct |
2 ms |
2076 KB |
Output is correct |
7 |
Correct |
3 ms |
2084 KB |
Output is correct |
8 |
Correct |
3 ms |
2212 KB |
Output is correct |
9 |
Correct |
12 ms |
4808 KB |
Output is correct |
10 |
Correct |
10 ms |
4168 KB |
Output is correct |
11 |
Correct |
16 ms |
5532 KB |
Output is correct |
12 |
Correct |
2 ms |
1544 KB |
Output is correct |
13 |
Correct |
1 ms |
1544 KB |
Output is correct |
14 |
Correct |
1 ms |
1544 KB |
Output is correct |
15 |
Correct |
1 ms |
1544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
5144 KB |
Output is correct |
2 |
Correct |
22 ms |
5256 KB |
Output is correct |
3 |
Correct |
22 ms |
5244 KB |
Output is correct |
4 |
Correct |
13 ms |
3288 KB |
Output is correct |
5 |
Correct |
16 ms |
4844 KB |
Output is correct |
6 |
Correct |
15 ms |
3664 KB |
Output is correct |
7 |
Correct |
14 ms |
3772 KB |
Output is correct |
8 |
Correct |
12 ms |
3576 KB |
Output is correct |
9 |
Correct |
15 ms |
3708 KB |
Output is correct |
10 |
Correct |
11 ms |
3228 KB |
Output is correct |
11 |
Correct |
12 ms |
3508 KB |
Output is correct |
12 |
Correct |
17 ms |
3132 KB |
Output is correct |
13 |
Correct |
15 ms |
3132 KB |
Output is correct |
14 |
Correct |
15 ms |
3156 KB |
Output is correct |
15 |
Correct |
14 ms |
3392 KB |
Output is correct |
16 |
Correct |
15 ms |
3252 KB |
Output is correct |
17 |
Correct |
16 ms |
3216 KB |
Output is correct |
18 |
Correct |
18 ms |
3332 KB |
Output is correct |
19 |
Correct |
19 ms |
3268 KB |
Output is correct |
20 |
Correct |
13 ms |
4364 KB |
Output is correct |
21 |
Correct |
17 ms |
4256 KB |
Output is correct |
22 |
Correct |
15 ms |
3784 KB |
Output is correct |
23 |
Correct |
14 ms |
3772 KB |
Output is correct |
24 |
Correct |
17 ms |
3888 KB |
Output is correct |
25 |
Correct |
13 ms |
3912 KB |
Output is correct |
26 |
Correct |
15 ms |
4028 KB |
Output is correct |
27 |
Correct |
18 ms |
4324 KB |
Output is correct |
28 |
Correct |
14 ms |
3536 KB |
Output is correct |
29 |
Correct |
13 ms |
3704 KB |
Output is correct |
30 |
Correct |
14 ms |
3724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
5128 KB |
Output is correct |
2 |
Correct |
25 ms |
4776 KB |
Output is correct |
3 |
Correct |
26 ms |
5296 KB |
Output is correct |
4 |
Correct |
17 ms |
3328 KB |
Output is correct |
5 |
Correct |
12 ms |
4296 KB |
Output is correct |
6 |
Correct |
13 ms |
3688 KB |
Output is correct |
7 |
Correct |
17 ms |
3820 KB |
Output is correct |
8 |
Correct |
14 ms |
3912 KB |
Output is correct |
9 |
Correct |
15 ms |
3788 KB |
Output is correct |
10 |
Correct |
12 ms |
3268 KB |
Output is correct |
11 |
Correct |
13 ms |
3352 KB |
Output is correct |
12 |
Correct |
13 ms |
3180 KB |
Output is correct |
13 |
Correct |
17 ms |
3172 KB |
Output is correct |
14 |
Correct |
16 ms |
3236 KB |
Output is correct |
15 |
Correct |
16 ms |
3272 KB |
Output is correct |
16 |
Correct |
16 ms |
3280 KB |
Output is correct |
17 |
Correct |
17 ms |
3216 KB |
Output is correct |
18 |
Correct |
18 ms |
3232 KB |
Output is correct |
19 |
Correct |
17 ms |
3192 KB |
Output is correct |
20 |
Correct |
14 ms |
4388 KB |
Output is correct |
21 |
Correct |
13 ms |
4288 KB |
Output is correct |
22 |
Correct |
14 ms |
3804 KB |
Output is correct |
23 |
Correct |
18 ms |
3796 KB |
Output is correct |
24 |
Correct |
16 ms |
3780 KB |
Output is correct |
25 |
Correct |
15 ms |
3908 KB |
Output is correct |
26 |
Correct |
17 ms |
3884 KB |
Output is correct |
27 |
Correct |
19 ms |
4260 KB |
Output is correct |
28 |
Correct |
13 ms |
4100 KB |
Output is correct |
29 |
Correct |
17 ms |
4144 KB |
Output is correct |
30 |
Correct |
12 ms |
3832 KB |
Output is correct |
31 |
Correct |
1 ms |
1536 KB |
Output is correct |
32 |
Correct |
2 ms |
1580 KB |
Output is correct |
33 |
Correct |
2 ms |
1548 KB |
Output is correct |
34 |
Correct |
2 ms |
1536 KB |
Output is correct |
35 |
Correct |
2 ms |
1536 KB |
Output is correct |
36 |
Correct |
1 ms |
1540 KB |
Output is correct |
37 |
Correct |
0 ms |
1544 KB |
Output is correct |
38 |
Correct |
2 ms |
1544 KB |
Output is correct |
39 |
Correct |
2 ms |
1548 KB |
Output is correct |
40 |
Correct |
1 ms |
1536 KB |
Output is correct |
41 |
Correct |
1 ms |
1544 KB |
Output is correct |
42 |
Correct |
1 ms |
1548 KB |
Output is correct |