#include <bits/stdc++.h>
using namespace std;
#include "supertrees.h"
#include <vector>
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> ans (n, vector < int > (n));
vector < pair < int, int > > dsu (n);
for (int i = 0; i < n; ++i) dsu[i].first = i, dsu[i].second = 1;
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
if (p[i][j] == 1)
{
int ci = dsu[i].first, cj = dsu[i].first;
while (dsu[ci].first != -1) ci = dsu[ci].first;
while (dsu[cj].first != -1) cj = dsu[cj].first;
if (ci != cj)
{
ans[i][j] = ans[j][i] = 1;
if (dsu[ci].second < dsu[cj].second) swap (ci, cj);
dsu[cj].first = ci;
dsu[ci].second += dsu[cj].second;
}
}
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
if (p[i][j] == 0)
{
int ci = dsu[i].first, cj = dsu[i].first;
while (dsu[ci].first != -1) ci = dsu[ci].first;
while (dsu[cj].first != -1) cj = dsu[cj].first;
if (ci == cj) return 0;
}
build (ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
1038 ms |
504 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
1038 ms |
504 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1036 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1058 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
1038 ms |
504 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
1038 ms |
504 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |