# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
949965 | irmuun | Connecting Supertrees (IOI20_supertrees) | C++17 | 172 ms | 22280 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<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int construct(vector<vector<int>>p){
int n=p.size();
bool a[4];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j) continue;
a[p[i][j]]=true;
}
}
vector<vector<int>>b(n,vector<int>(n,0));
if(!a[2]&&!a[3]){
vector<bool>used(n,0);
vector<int>ver;
for(int i=0;i<n;i++){
if(!used[i]){
queue<int>q;
q.push(i);
used[i]=true;
while(!q.empty()){
int x=q.front();
ver.pb(x);
q.pop();
for(int j=0;j<n;j++){
if(p[x][j]==1&&!used[j]){
used[j]=true;
q.push(j);
}
}
}
for(auto x:ver){
for(auto y:ver){
if(x!=y&&p[x][y]!=1){
return 0;
}
}
}
for(int j=1;j<ver.size();j++){
b[ver[j]][ver[j-1]]=1;
b[ver[j-1]][ver[j]]=1;
}
ver.clear();
}
}
build(b);
return 1;
}
if(a[0]&&!a[1]&&a[2]&&!a[3]){
vector<bool>used(n,0);
vector<int>ver;
for(int i=0;i<n;i++){
if(!used[i]){
queue<int>q;
q.push(i);
used[i]=true;
while(!q.empty()){
int x=q.front();
ver.pb(x);
q.pop();
for(int j=0;j<n;j++){
if(p[x][j]==2&&!used[j]){
used[j]=true;
q.push(j);
}
}
}
for(auto x:ver){
for(auto y:ver){
if(x!=y&&p[x][y]!=2){
return 0;
}
}
}
for(int j=1;j<ver.size();j++){
b[ver[j]][ver[j-1]]=1;
b[ver[j-1]][ver[j]]=1;
}
if(ver.size()>1){
b[ver[0]][ver.back()]=1;
b[ver.back()][ver[0]]=1;
}
ver.clear();
}
}
build(b);
return 1;
}
return 0;
}
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... |