This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "supertrees.h"
#include <vector>
#include <iostream>
#define pb push_back
using namespace std;
int find_head(vector<int> a,int val){
if(a[val] == val)
return val;
return find_head(a,a[val]);
}
int find_leaf(vector<int> a,int val){
if(a[val] == val)
return val;
return find_leaf(a,a[val]);
}
int construct(vector<vector<int>> p) {
// cout << "started" << endl;
int n = p.size();
vector<vector<int>> ans;
vector<int> temp(n,0);
vector<int> head;
vector<int> leaf;
for (int i = 0; i < n; i++) {
ans.pb(temp);
head.pb(i);
leaf.pb(i);
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j] >= 1){
int c = min(i,j),d = max(i,j);
int h_c = find_head(head,c);
int h_d = find_head(head,d);
if(h_c != h_d){
ans[h_c][h_d] = 1;
ans[h_d][h_c] = 1;
}
head[h_d] = h_c;
leaf[h_c] = find_leaf(leaf,d);
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
int c = min(i,j),d = max(i,j);
int h_c = find_head(head,c);
int h_d = find_head(head,d);
int l_c = find_leaf(leaf,c);
int l_d = find_leaf(leaf,d);
if(p[i][j] == 2){
ans[h_c][l_d] = 1;
ans[l_d][h_c] = 1;
}
if(p[i][j] == 0 and h_c == h_d){
return 0;
}
if(p[i][j] >= 1 and h_c != h_d){
return 0;
}
}
}
build(ans);
// cout << "finish" << endl;
return 1;
}
Compilation message (stderr)
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:56:8: warning: unused variable 'l_c' [-Wunused-variable]
56 | int l_c = find_leaf(leaf,c);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |