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 <stdio.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
#define long long long
#define fi first
#define se second
typedef pair<int,int> ii;
int n;
int parent[1503];
int A[1503][1503];
vector<int> mem[1503];
void print()
{
// for(int i = 0; i < n; i++)
// {
// printf(" ");
// for(int j = 0; j < n; j++)
// printf("%d ", A[i][j]);
// printf("\n");
// }
// printf("\n");
}
void initialize(int N)
{
n = N;
for(int i = 0; i < n; i++) mem[i] = {i}, parent[i] = i;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(i != j)
A[i][j] = 1;
print();
}
int hasEdge(int u, int v)
{
// printf("%d %d %d %d\n", u, v, parent[u], parent[v]);
u = parent[u]; v = parent[v];
if(A[u][v] == 1)
{
for(int i = 0; i < n; i++)
{
A[u][i] += A[v][i];
A[i][u] += A[i][v];
A[v][i] = A[i][v] = 0;
}
A[u][u] = 0;
for(int x : mem[v])
{
mem[u].push_back(x);
parent[x] = u;
// printf(" X : %d %d\n", x, parent[x]);
}
// print();
return 1;
}
else
{
A[u][v]--;
A[v][u]--;
// print();
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... |