# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
290862 | davi_bart | Game (IOI14_game) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
set<int> p[1600];
int arc[42][42];
int rad,N;
//bool ricalcola=1;
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(42,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;
auto y=p[pos].lower_bound(rad*ga);
if(y==p[pos].end())continue;
while((*y)>=rad*ga && (*y)<rad*(ga+1)){
q.push(*y);
y++;
if(y==p[pos].end())break;
}
}
bool ok=1;
for(int i=0;i<rad;i++){
if(ga*rad+i>=N)break;
if(vis[i]==0){
ok=0;
break;
}
}
if(ok==0){
p[u].insert(v);
p[v].insert(u);
return 1;
}
return 0;
}
p[u].erase(v);
p[v].erase(u);
arc[ga][gb]--;
arc[gb][ga]--;
bool ok=0;
if(arc[ga][gb])ok=1;
vector<bool> vis(42,0);
queue<int> q;
q.push(ga);
while(!q.empty() && ok==0){
int pos=q.front();
q.pop();
if(pos==gb){
ok=1;
break;
}
if(vis[pos])continue;
vis[pos]=1;
arc[ga][pos]++;
for(int i=0;i<=((N-1)/rad);i++){
if(arc[pos][i]){
if(i==gb){
ok=1;
break;
}
if(vis[i]==0)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;
}