# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
420152 | Belgutei | Connecting Supertrees (IOI20_supertrees) | C++17 | 506 ms | 24016 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;
#define mk make_pair
#define ff first
#define ss second
#define pb push_back
map<int,int> mp;
vector<int> tree[1005];
int construct(std::vector<std::vector<int> > p) {
int n=p.size();
std::vector<std::vector<int> > answer;
answer.resize(n);
bool c1=0,cc=0;
for(int i=0; i<p.size(); i++){
for(int j=0; j<p[i].size(); j++){
answer[i].resize(n);
if(p[i][j]>=2) c1=1;
if(i==j) continue;
if(p[i][j]==1 || p[i][j]==3) cc=1;
}
}
if(c1==0){
// subtask 1,2
int cnt=0;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i==j) continue;
if(p[i][j]==1){
if(mp[i]==0 && mp[j]==0){
cnt++;
mp[i]=cnt;
mp[j]=cnt;
tree[cnt].pb(i);
tree[cnt].pb(j);
continue;
}
if(mp[i]==0){
mp[i]=mp[j];
tree[mp[i]].pb(i);
continue;
}
if(mp[j]==0){
mp[j]=mp[i];
tree[mp[j]].pb(j);
continue;
}
if(mp[i]!=mp[j]) return 0;
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i==j) continue;
if(mp[i]!=mp[j] && p[i][j]==1) return 0;
if(mp[i]==mp[j] && p[i][j]==0 && mp[i]!=0) return 0;
}
}
for(int i=1; i<=cnt; i++){
for(int j=1; j<tree[i].size(); j++){
answer[tree[i][j]][tree[i][j-1]]=1;
answer[tree[i][j-1]][tree[i][j]]=1;
}
}
build(answer);
return 1;
}
if(cc==0){
// subtask 2
int cnt=0;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i==j) continue;
if(p[i][j]==2){
if(mp[i]==0 && mp[j]==0){
cnt++;
mp[i]=cnt;
mp[j]=cnt;
tree[cnt].pb(i);
tree[cnt].pb(j);
continue;
}
if(mp[i]==0){
mp[i]=mp[j];
tree[mp[i]].pb(i);
continue;
}
if(mp[j]==0){
mp[j]=mp[i];
tree[mp[j]].pb(j);
continue;
}
if(mp[i]!=mp[j]) return 0;
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i==j) continue;
if(mp[i]!=mp[j] && p[i][j]==2) return 0;
if(mp[i]==mp[j] && p[i][j]==0 && mp[i]!=0) return 0;
}
}
for(int i=1; i<=cnt; i++){
if(tree[i].size()==2) return 0;
for(int j=1; j<tree[i].size(); j++){
answer[tree[i][j]][tree[i][j-1]]=1;
answer[tree[i][j-1]][tree[i][j]]=1;
}
answer[tree[i][0]][tree[i][tree[i].size()-1]]=1;
answer[tree[i][tree[i].size()-1]][tree[i][0]]=1;
}
build(answer);
return 1;
}
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... |