#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int pa[N];
int fp(int u) { return pa[u] = (u == pa[u]) ? u : fp(pa[u]); }
int construct(vector<vector<int>> p)
{
int n = p.size();
vector<vector<int>> ans(n, vector<int>(n));
for (int i=0 ; i<n ; i++) pa[i] = i;
for (int i=0 ; i<n ; i++)
{
for (int j=i+1 ; j<n ; j++)
{
if (p[i][j] == 1)
{
ans[i][j] = ans[j][i] = 1;
pa[fp(i)] = fp(j);
}
}
}
for (int i=0 ; i<n ; i++)
{
vector<int> loop;
for (int j=i+1 ; j<n ; j++)
{
if (p[i][j] == 2 && fp(i) != fp(j))
{
loop.push_back(j);
pa[fp(i)] = fp(j);
}
}
if (loop.empty()) continue;
int prv = i;
for (int cur : loop)
{
ans[prv][cur] = ans[cur][prv] = 1;
prv = cur;
}
ans[loop.back()][i] = ans[i][loop.back()] = 1;
}
for (int i=0 ; i<n ; i++)
{
for (int j=i+1 ; j<n ; j++)
{
if (p[i][j] == 3)
{
return 0;
}
}
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 1 to 4, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |