#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int MXN = 1005;
vector<int> par_line(MXN, 0), par_comp(MXN, 0), line[MXN], cycle_vertex[MXN];
int root(int i, vector<int> &par) {
while(i != par[par[i]]) {
par[i] = par[par[i]];
i = par[par[i]];
}
return i;
}
void mergeset(int a, int b, vector<int> &par) {
par[root(a, par)] = root(b, par);
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
par_line[i] = i;
par_comp[i] = i;
}
for(int i = 0; i < n; i++) {
bool cycle_data = false, found_comp = false;
for(int j = 0; j < n; j++) {
if(i == j) continue;
if(p[i][j] != 0) {
if(p[i][j] == 3) {
return 1;
}
found_comp = true;
if(p[i][j] == 2) {
cycle_data = true;
if(root(i, par_comp) != root(j, par_comp)) {
mergeset(i, j, par_comp);
}
continue;
}
if(root(i, par_line) != root(j, par_line)) {
mergeset(i, j, par_line);
}
}
}
if(!cycle_data) {
par_comp[i] = -1;
}
if(!found_comp) {
par_line[i] = -1;
}
}
for(int i = 0; i < n; i++) {
if(par_line[i] != -1) {
line[root(i, par_line)].push_back(i);
}
}
for(int i = 0; i < n; i++) {
int sz = line[i].size();
if(sz) {
if(par_comp[line[i][0]] != -1){
cycle_vertex[root(line[i][0], par_comp)].push_back(line[i][0]);
}
}
for(int j = 0; j < sz - 1; j++) {
int x = line[i][j], y = line[i][j + 1];
answer[x][y] = answer[y][x] = 1;
}
}
for(int i = 0; i < n; i++) {
int sz = cycle_vertex[i].size();
if(sz >= 3) {
cycle_vertex[i].push_back(cycle_vertex[i][0]);
for(int j = 0; j < sz; j++) {
int x = cycle_vertex[i][j], y = cycle_vertex[i][j + 1];
answer[x][y] = answer[y][x] = 1;
}
}
}
build(answer);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
252 ms |
22264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
252 ms |
22264 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1280 KB |
Output is correct |
13 |
Correct |
239 ms |
22264 KB |
Output is correct |
14 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
62 ms |
5880 KB |
Output is correct |
5 |
Correct |
245 ms |
22264 KB |
Output is correct |
6 |
Correct |
237 ms |
22140 KB |
Output is correct |
7 |
Correct |
248 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
61 ms |
5928 KB |
Output is correct |
10 |
Correct |
248 ms |
22136 KB |
Output is correct |
11 |
Correct |
234 ms |
22136 KB |
Output is correct |
12 |
Correct |
252 ms |
22136 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
65 ms |
5884 KB |
Output is correct |
17 |
Correct |
239 ms |
22136 KB |
Output is correct |
18 |
Correct |
242 ms |
22136 KB |
Output is correct |
19 |
Correct |
238 ms |
22136 KB |
Output is correct |
20 |
Correct |
235 ms |
22136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
252 ms |
22264 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1280 KB |
Output is correct |
13 |
Correct |
239 ms |
22264 KB |
Output is correct |
14 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
252 ms |
22264 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1280 KB |
Output is correct |
13 |
Correct |
239 ms |
22264 KB |
Output is correct |
14 |
Incorrect |
1 ms |
384 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |