#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;
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;
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;
imam.erase(uzimam);
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);
if(dfs2(i)) return true;
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]]++;
imam.emplace(uzimam);
p[node]=-1;
p[i]=node;
}
}
return false;
}
int v;
void uradi(int 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);
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);
}
uradi(poc);
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1544 KB |
Output is correct |
2 |
Incorrect |
2 ms |
1536 KB |
Wrong Answer [7] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
5052 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1536 KB |
Output is correct |
2 |
Correct |
1 ms |
1544 KB |
Output is correct |
3 |
Incorrect |
1 ms |
1536 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
5052 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
4944 KB |
Wrong Answer [7] |
2 |
Halted |
0 ms |
0 KB |
- |