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 "supertrees.h"
using namespace std;
constexpr static int MXN = 1e3 + 5;
struct Node
{
int head, tail, size, nxt;
Node(int i) : head(i), tail(i), size(1), nxt(-1) {}
Node() : Node(-1) {}
};
Node node[MXN];
void merge(int a, int b);
int construct(vector<vector<int>> p)
{
int n = p.size();
vector<vector<int>> answer(n, vector<int>(n));
for (int i = 0; i < n; i++)
node[i] = Node(i);
for (int i = 0; i < n; i++)
{
for (int j = i+1; j < n; j++)
{
if (p[i][j] && node[i].head != node[j].head)
{
merge(node[i].head, node[j].head);
answer[i][j] = answer[j][i] = 1;
}
}
}
for (int i = 0; i < n; i++)
for (int j = i+1; j < n; j++)
if (!p[i][j] && node[i].head == node[j].head)
return 0;
build(answer);
return 1;
}
void merge(int a, int b)
{
if (node[a].size < node[b].size) swap(a, b);
node[a].size += node[b].size;
node[node[a].tail].nxt = b;
node[a].tail = node[b].tail;
for (;b!=-1;b=node[b].nxt)
node[b].head = a;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |