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"
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;
int N;
vi parent(1502);
vvi asked(1502,vi(1502,-1));
vi asked_cnt(1502,0);
int get_parent(int pos){
if(parent[pos] == pos)return pos;
return get_parent(parent[pos]);
}
void initialize(int n) {
N = n;
FOR(i,0,N)parent[i] = i;
asked = vvi(1502,vi(1502,-1));
asked_cnt = vi(1502,0);
}
void set_asked(int u,int v, int val){
asked[u][v] = val;
asked[v][u] = val;
}
int hasEdge(int u, int v) {
if(u==v)return 1;
if(asked[u][v] != -1)return asked[u][v];
asked_cnt[u]++;
asked_cnt[v]++;
int a = get_parent(u), b = get_parent(v);
if(a == b){
set_asked(u,v,1);
return 1;
}
// if(asked_cnt[u] > N-1 || asked_cnt[v] > N-1){
if(min(u,v) == 0 && max(u,v) == N-1){
parent[a] = parent[b];
set_asked(u,v,1);
return 1;
}
set_asked(u,v,0);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |