이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define ld long double
set<int> p[1600];
bool arc[42][42];
int rad;
void sist(int a,int b){
bool ok=0;
for(int i=rad*a;i<rad*(a+1);i++){
for(int j=rad*b;j<rad*(b+1);j++){
if(p[i].find(j)!=p[i].end())ok=1;
}
}
arc[a][b]=arc[b][a]=ok;
}
int hasEdge(int u, int v) {
int ga=u/rad,gb=v/rad;
if(ga==gb){
p[u].erase(v);
p[v].erase(u);
vector<bool> vis(50,0);
queue<int> q;
q.push(u);
while(!q.empty()){
int pos=q.front();
q.pop();
if(pos/rad!=ga)continue;
if(vis[pos%rad])continue;
vis[pos%rad]=1;
for(int x:p[pos])q.push(x);
}
bool ok=1;
for(int i=0;i<rad;i++)if(vis[i]==0)ok=0;
if(ok==0){
p[u].insert(v);
p[v].insert(u);
return 1;
}
return 0;
}
p[u].erase(v);
p[v].erase(u);
sist(ga,gb);
vector<bool> vis(50,0);
queue<int> q;
q.push(ga);
bool ok=0;
while(!q.empty()){
int pos=q.front();
q.pop();
if(pos==gb){
ok=1;
break;
}
if(vis[pos])continue;
vis[pos]=1;
for(int i=0;i<rad;i++){
if(arc[pos][i]==1)q.push(i);
}
}
if(ok==0){
p[u].insert(v);
p[v].insert(u);
arc[ga][gb]=arc[gb][ga]=1;
return 1;
}
return 0;
}
/*
4
0 3
1 0
0 2
3 1
1 2
2 3
*/
void initialize(int n){
rad=min(40,n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
p[i].insert(j);
}
}
for(int i=0;i<rad;i++){
for(int j=0;j<rad;j++){
arc[i][j]=1;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |