# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
585897 | John3_141592 | Connecting Supertrees (IOI20_supertrees) | C++14 | 189 ms | 27872 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 "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int dad[10060],asd[10003][10003];
int Find(int x){
return x==dad[x]?x:dad[x]=Find(dad[x]);
}
void Union(int a,int b){
a=Find(a),b=Find(b);
if(a>b) swap(a,b);
dad[b]=a;
}
int construct(std::vector<std::vector<int>> p) {
int n=p.size();
vector <vector <int> > answer;
bool band=false;
for(int i=1;i<=n;i++) dad[i]=i;
for(int i=0;i<n;i++){
for(int j=0;j<p[i].size();j++){
if(p[i][j]==2) band=true;
if(p[i][j]) Union(i,j);
}
}
if(!band){
for(int i=0;i<n;i++){
if(i==Find(i)) continue;
asd[i][Find(i)]=asd[Find(i)][i]=1;
}
for(int i=0;i<n;i++){
vector <int> qwe;
for(int j=0;j<n;j++){
qwe.push_back(asd[i][j]);
}
answer.push_back(qwe);
}
}else{
vector <int> grafo[10000];
for(int i=0;i<n;i++){
if(i==Find(i)) continue;
grafo[Find(i)].push_back(i);
}
for(int i=0;i<n;i++){
if(grafo[i].empty()) continue;
asd[i][grafo[i][0]]=asd[grafo[i][0]][i]=1;
for(int j=1;j<grafo[i].size();j++) asd[grafo[i][j-1]][grafo[i][j]]=asd[grafo[i][j]][grafo[i][j-1]]=1;
asd[i][grafo[i].back()]=asd[grafo[i].back()][i]=1;
}
for(int i=0;i<n;i++){
vector <int> qwe;
for(int j=0;j<n;j++){
qwe.push_back(asd[i][j]);
}
answer.push_back(qwe);
}
}
build(answer);
return 1;
}
//#include "supertrees.h"
//#include <vector>
//
//int construct(std::vector<std::vector<int>> p) {
// int n = p.size();
// std::vector<std::vector<int>> answer;
// for (int i = 0; i < n; i++) {
// std::vector<int> row;
// row.resize(n);
// answer.push_back(row);
// }
// build(answer);
// 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... |