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;
const int N=300050;
int n,k,l[N],r[N];
vector<int> adj[N],radj[N];
void init(int nn, int kk) {
n=nn; k=kk;
for (int i=0;i<=k;i++) l[i]=i,r[i]=i+1;
for (int i=k+1;i<=n;i++) l[i]=0,r[i]=k-1;
for (int i=0;i<=n;i++) adj[i].clear(),radj[i].clear();
}
bool addedge(int u,int v){
//cerr<<u<<":"<<l[u]<<"-"<<r[u]<<"->"<<v<<":"<<l[v]<<"-"<<r[v]<<"\n";
if (r[u]<=l[v]) return 0;
if (l[u]>=r[v]) return 1;
if (r[v]<=(l[u]+r[u])/2){
r[u]=(l[u]+r[u])/2;
for (int i:radj[u]) if (addedge(i,u)) return 1;
}else if (l[u]>(l[v]+r[v])/2){
l[v]=(l[v]+r[v])/2+1;
for (int i:adj[v]) if (addedge(v,i)) return 1;
}
return 0;
}
int add_teleporter(int u, int v) {
u++;
if (v>k) v++;
adj[u].push_back(v);
radj[v].push_back(u);
return addedge(u,v);
}
/*
6 5 3
3 4
5 0
4 5
5 3
1 4
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |