# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
625299 | Trunkty | Connecting Supertrees (IOI20_supertrees) | C++14 | 214 ms | 24080 KiB |
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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
//#define int ll
#include "supertrees.h"
int root[1005];
vector<int> ans[1005];
int findroot(int x){
if(root[x]!=x){
root[x] = findroot(root[x]);
}
return root[x];
}
void domerge(int a, int b){
a = findroot(a);
b = findroot(b);
root[a] = b;
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ret;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
ret.push_back(row);
}
for(int i=0;i<n;i++){
root[i] = i;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j]){
domerge(i,j);
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j]==0 and findroot(i)==findroot(j)){
return 0;
}
}
}
for(int i=0;i<n;i++){
ans[findroot(i)].push_back(i);
}
for(int i=0;i<n;i++){
for(int j=1;j<ans[i].size();j++){
ret[ans[i][j-1]][ans[i][j]] = 1;
ret[ans[i][j]][ans[i][j-1]] = 1;
}
}
build(ret);
return 1;
}
Compilation message (stderr)
# | 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... |