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 <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>
#include <iterator>
#include <stack>
#include <map>
#include <math.h>
#include <bitset>
#include <deque>
#include <string>
#include <tuple>
#include <queue>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#define pi 3.141592653589793238
#define ll long long
#define ld long double
#define rep(i, a, b) for (long long i = a; i <= b; i++)
#define mod 1000000007ll
#define INF 1000000000000000000
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin (), (x).end ()
#define sz(x) (ll) (x).size ()
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define rank rnk
#define log lg
#define fast \
ios_base::sync_with_stdio (false); \
cin.tie (NULL); \
cout.tie (NULL)
using namespace std;
int n;
vector <set<int>> adj;
vector <bool> visited;
void dfs(int v)
{
visited[v]=true;
for(auto u:adj[v])
if(!visited[u])
dfs(u);
}
bool is_connected()
{
visited.assign(n,false);
dfs(0);
bool ok=true;
rep(i,0,n-1)
ok=(ok&visited[i]);
return ok;
}
void initialize(int _n)
{
n=_n;
rep(i,0,n-1)
{
set <int> s;
rep(j,0,n-1)
if(j!=i)
s.insert(j);
adj.pb(s);
}
}
int hasEdge(int u, int v)
{
adj[v].erase(u);
adj[u].erase(v);
if(is_connected())
return false;
else
{
adj[u].insert(v);
adj[v].insert(u);
return true;
}
}
// signed main()
// {
// fast;
// initialize(4);
// cout<<hasEdge(0,3);
// cout<<hasEdge(0,1);
// cout<<hasEdge(0,2);
// cout<<hasEdge(1,3);
// cout<<hasEdge(1,2);
// cout<<hasEdge(2,3);
// 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... |