# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
902259 | Ghulam_Junaid | Game (IOI14_game) | C++17 | 1 ms | 2648 KiB |
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>
// #include "grader.cpp"
using namespace std;
const int MXN = 1505;
int n, par[MXN], seen[MXN][MXN];
vector<int> S[MXN];
int root(int v){
return ((par[v] == -1) ? (v) : (par[v] = root(par[v])));
}
void merge(int u, int v){
if ((u = root(u)) == (v = root(v)))
return;
if (S[u].size() > S[v].size())
swap(u, v);
par[u] = v;
for (int x : S[u])
S[v].push_back(x);
S[u].clear();
}
void initialize(int N){
n = N;
for (int i=0; i<n; i++){
S[i].push_back(i);
par[i] = -1;
}
}
int hasEdge(int u, int v){
seen[u][v] = 1;
u = root(u), v = root(v);
if (u == v) return 0;
int cnt = 0;
for (int x : S[u])
for (int y : S[v])
cnt += seen[x][y];
if (cnt == (S[u].size() * S[v].size()) ){
merge(u, v);
return 1;
}
return 0;
}
// int main(){
// int n;
// cin >> n;
// initialize(n);
// for (int i=0; i<(n * (n - 1)) / 2; i++){
// int u, v;
// cin >> u >> v;
// cout << hasEdge(u, v) << endl;
// }
// }
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |