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>
#define fi first
#define se second
using namespace std;
int n;
vector<vector<int>> adj;
vector<unordered_set<int>> unknown;
void initialize(int N) {
n = N;
adj = vector<vector<int>>(n);
unknown = vector<unordered_set<int>>(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (j != i) unknown[i].insert(j);
}
}
}
void dfs(int u, vector<bool>& visited) {
visited[u] = true;
for (int v: adj[u]) {
if (!visited[v]) dfs(v, visited);
}
for (int v: unknown[u]) {
if (!visited[v]) dfs(v, visited);
}
}
bool connected(int u, int v) {
vector<bool> visited(n, false);
dfs(u, visited);
return visited[v];
}
int hasEdge(int u, int v) {
unknown[u].erase(v);
unknown[v].erase(u);
if (!connected(u, v)) {
adj[u].push_back(v);
adj[v].push_back(u);
return 1;
}
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... |