#include "supertrees.h"
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
struct DSU{
int n;
vector<int> par, s;
DSU(int N){
n = N;
s.assign(n, 1), par.resize(n);
iota(all(par), 0);
}
int get(int a){
return par[a] = (a == par[a] ? a : get(par[a]));
}
void uni(int a, int b){
a = get(a), b = get(b);
if(s[a] > s[b])swap(a, b);
par[a] = b, s[b] += s[a];
}
int get_size(int a){
return s[get(a)];
}
bool same_set(int a, int b){
return get(a) == get(b);
}
};
const int N = 1005;
vector<int> adj[N], adj2[N];
vector<int> component;
bool vis[N];
int r[N];
void dfs(int u){
component.pb(u);
vis[u] = true;
for(int v: adj[u])dfs(v);
}
int construct(vector<vector<int>> p){
int n = sz(p);
vector<vector<int>> ans(n, vector<int>(n, 0));
DSU d(n);
for(int i = 0;i < n; ++i){
for(int j = 0;j < n; ++j){
if(p[i][j] == 2 && !d.same_set(i, j)){
adj[i].pb(j);
adj[j].pb(i);
d.uni(i, j);
}
}
}
for(int i = 0;i < n; ++i){
if(!vis[i]){
component.clear();
dfs(i);
for(int i = 0;i < sz(component); ++i){
ans[component[i]][component[(i + 1) % sz(component)]] = ans[component[(i + 1) % sz(component)]][component[i]] = 1;
}
int prev = -1;
for(int u: component){
for(int v: adj2[u]){
if(!d.same_set(u, v)){
ans[u][v] = ans[v][u] = 1;
d.uni(u, v);
}
}
if(prev != -1)d.uni(prev, u);
prev = u;
}
}
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
b[0][0] is not 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
b[0][0] is not 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
b[0][0] is not 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
b[0][0] is not 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
b[0][0] is not 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
b[0][0] is not 0 |
2 |
Halted |
0 ms |
0 KB |
- |