#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int construct(vector<vector<int>> p)
{
int n = p.size();
vector<bool> used(n, false);
vector<vector<int>> adjmatrix(n, vector<int> (n, 0));
for(int i = 0; i < n; i++)
{
if(used[i]) continue;
used[i] = true;
//Collect the component:
vector<int> component(0);
for(int j = 0; j < n; j++)
{
if(p[i][j])
{
component.push_back(j);
used[j] = true;
}
if(p[i][j] == 3)
{
return 0;
}
}
//Build the forest:
vector<bool> tree(component.size(), false);
vector<vector<int>> forest(0);
for(int j = 0; j < (int) component.size(); j++)
{
if(tree[j]) continue;
vector<int> t(0);
for(int k = 0; k < (int) component.size(); k++)
{
if(p[j][k] == 1)
{
t.push_back(k);
tree[k] = true;
used[k] = true;
}
}
forest.push_back(t);
//Build the tree:
for(int k = 0; k < (int) t.size()-1; k++)
{
adjmatrix[t[k]][t[k+1]] = 1;
adjmatrix[t[k+1]][t[k]] = 1;
}
}
//Connect the trees:
if(forest.size() > 2)
{
for(int j = 0; j < (int) forest.size()-1; j++)
{
adjmatrix[forest[j][0]][forest[j+1][0]] = 1;
adjmatrix[forest[j+1][0]][forest[j][0]] = 1;
}
adjmatrix[forest[0][0]][forest[forest.size()-1][0]] = 1;
adjmatrix[forest[forest.size()-1][0]][forest[0][0]] = 1;
}
}
build(adjmatrix);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1208 KB |
Output is correct |
7 |
Correct |
152 ms |
23376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1208 KB |
Output is correct |
7 |
Correct |
152 ms |
23376 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1248 KB |
Output is correct |
13 |
Correct |
159 ms |
23384 KB |
Output is correct |
14 |
Incorrect |
1 ms |
212 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 |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Incorrect |
0 ms |
296 KB |
Too few ways to get from 1 to 4, should be 1 found 0 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1208 KB |
Output is correct |
7 |
Correct |
152 ms |
23376 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1248 KB |
Output is correct |
13 |
Correct |
159 ms |
23384 KB |
Output is correct |
14 |
Incorrect |
1 ms |
212 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 |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1208 KB |
Output is correct |
7 |
Correct |
152 ms |
23376 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1248 KB |
Output is correct |
13 |
Correct |
159 ms |
23384 KB |
Output is correct |
14 |
Incorrect |
1 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |