#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define pb push_back
#define popb pop_back
#define ff first
#define ss second
vi par;
vi rnk;
int findset(int i)
{
if(par[i] == i)
return i;
return findset(par[i]) ;
}
void unite(int i, int j)
{
if(findset(i) == findset(j))
return;
int x = findset(i);
int y = findset(j);
if(rnk[x] < rnk[y])
swap(x,y);
par[y] = x;
if(rnk[x] == rnk[y])
rnk[x] ++;
return ;
}
int construct(vector<vi> p)
{
int n = p.size();
vector<vi> b;
for (int i = 0; i < n; i++)
{
vi row;
for(int j = 0; j <n; j ++)
{
par.pb(j);
rnk.pb(1);
row.pb(0);
}
b.pb(row);
}
for(int i = 0; i <n; i ++)
{
for(int j = 0; j < n; j ++)
{
if(i == j)
continue;
if(p[i][j] > 0)
{
unite(i,j);
b[findset(i)][findset(j)] = 1;
}
}
}
for(int i = 0; i <n; i ++)
{
for(int j = 0; j < n; j ++)
{
if(i == j)
continue;
if(p[i][j] == 0 && findset(i) == findset(j))
return 0;
}
}
build(b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
b[0][0] is not 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
b[0][0] is not 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
b[0][0] is not 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
b[0][0] is not 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
b[0][0] is not 0 |
3 |
Halted |
0 ms |
0 KB |
- |