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;
#define ll int
#define F first
#define S second
#define sz(x) (ll)x.size()
#define endl "\n"
#define pb push_back
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
void printVct(vi &v){
for (ll i =0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
ll n;
vector <vi> adj;
void initialize(int N) {
n = N;
adj.assign(n,vi());
for (ll i =0; i<n; i++){
for (ll j =0; j<n; j++){
if (i == j) continue;
adj[i].pb(j);
}
}
}
vi vis;
ll dfs(ll u, ii &tested_edge){
vis[u] = 1;
ll ans = 1;
for (ll i= 0; i<sz(adj[u]); i++){
ll c = adj[u][i];
ii cur_edge = ii(u, c);
if (u > c) swap(cur_edge.F,cur_edge.S);
if (cur_edge == tested_edge) continue;
if (!vis[c]){
ans += dfs(c, tested_edge);
}
}
return ans;
}
void remove_edge(ll u, ll v){
ll pos = 0;
for (ll i =0; i<sz(adj[u]); i++){
if (adj[u][i] == v){
pos = i;
break;
}
}
adj[u].erase(adj[u].begin()+pos);
}
int hasEdge(int u, int v) {
// return 0;
if (u > v) swap(u,v);
ii tested_edge = ii(u,v);
vis.assign(n, 0);
ll x = dfs(0, tested_edge);
if (x == n){
//remove tested edge
remove_edge(u,v);
remove_edge(v,u);
return 0;
}
return 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... |