# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
336137 | bigDuck | Game (IOI14_game) | C++14 | 1095 ms | 13676 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<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#include "game.h"
multiset<int> g[1510];
int N;
void initialize(int n) {
N=n;
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
g[i].insert(j); g[j].insert(i);
}
}
}
int v[1510];
int is_bridge(int x, int y, int ac){
int n=N;
queue<int> q1, q2;
v[x]=ac; v[y]=ac+1;
q1.push(x); q2.push(y);
while((!q1.empty()) && (!q2.empty()) ){
int f1=q1.front(); q1.pop();
//cout<<"f1: "<<f1<<" ";
if( (v[f1]==(ac+1) ) ){
g[x].erase(g[x].find(y)); g[y].erase(g[y].find(x) );
//cout<<"\n"<<flush;
return 0;
}
v[f1]=ac;
for(auto it=g[f1].begin(); it!=g[f1].end(); it++){
//cout<<*it<<" ";
if( (v[*it]!=ac) && ( (*it)!=y) ){
//cout<<*it<<"g1 ";
if( v[*it]==(ac+1) ){
g[x].erase(g[x].find(y)); g[y].erase(g[y].find(x) );
//cout<<"\n"<<flush;
return 0;
}
v[*it]=ac;
q1.push(*it);
}
}
//cout<<"2x\n";
int f2=q2.front(); q2.pop();
//cout<<"f2: "<<f2<<" ";
if( (v[f2]==(ac) ) ){
g[x].erase(g[x].find(y)); g[y].erase(g[y].find(x) );
// cout<<"\n"<<flush;
return 0;
}
v[f2]=ac+1;
for(auto it=g[f2].begin(); it!=g[f2].end(); it++){
//cout<<*it<<" ";
if( (v[*it]!=(ac+1)) && ( (*it)!=x ) ){
if( v[*it]==(ac) ){
g[x].erase(g[x].find(y)); g[y].erase(g[y].find(x) );
//cout<<"\n"<<flush;
return 0;
}
v[*it]=ac+1;
q2.push(*it);
}
}
}
//cout<<"\n"<<flush;
return 1;
}
int ac=1;
int hasEdge(int u, int v) {
ac+=3;
return is_bridge(u, v, ac);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |