# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
803638 | 2023-08-03T05:12:56 Z | Warinchai | Connecting Supertrees (IOI20_supertrees) | C++14 | 1 ms | 212 KB |
#include "supertrees.h" #include <vector> #include<bits/stdc++.h> using namespace std; int sz; vector<vector<int> >v; vector<vector<int> >ans; int pr[1005]; int fp(int a){ if(pr[a]==a){ return a; } return pr[a]=fp(pr[a]); } void un(int a,int b){ if(fp(a)!=fp(b)){ ans[a][b]=1; ans[b][a]=1; pr[fp(b)]=fp(a); } } bool build_1(){ for(int i=0;i<sz;i++){ for(int j=i+1;j<sz;j++){ if(v[i][j]==1){ if(fp(i)!=fp(j)){ return 0; } un(i,j); } } } return 1; } int use_2[1005]; bool build_2(){ int count=0; vector<int>cy; for(int i=0;i<sz;i++){ for(int j=i+1;j<sz;j++){ if(v[i][j]==2){ if(use_2[i]==0){ use_2[i]=1; count++; cy.push_back(i); } if(use_2[j]==0){ use_2[j]=1; count++; cy.push_back(j); } } } } if(count<2){ return 0; } for(int i=0;i<cy.size()-1;i++){ un(cy[i],cy[i+1]); } un(cy[0],cy[cy.size()-1]); return 1; } bool check_0(){ for(int i=0;i<sz;i++){ for(int j=i+1;j<sz;j++){ if(v[i][j]==0&&fp(i)==fp(j))return 0; } } return 1; } int construct(vector<vector<int> > p) { //cout<<"work"<<endl; sz = p.size(); bool check=0; v.resize(sz); for(int i=0;i<sz;i++){ v[i].resize(sz); } for(int i=0;i<sz;i++){ for(int j=0;j<sz;j++){ //cout<<"i j "<<i<<" "<<j<<endl; v[i][j]=p[i][j]; if(p[i][j]!=p[j][i]||(i==j&&p[i][j]!=1)){ check=1; //cout<<"break"<<endl; break; } } } //cout<<"work"<<endl; if(check){ return 0; } //cout<<"work"<<endl; ans.resize(sz); for(int i=0;i<sz;i++){ ans[i].resize(sz); } for(int i=0;i<sz;i++){ pr[i]=i; } //cout<<"work"<<endl; if(!build_2()){ return 0; } if(!build_1()){ return 0; } if(!check_0()){ return 0; }else{ build(ans); } //cout<<"ans:"<<endl; return 1; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Answer gives possible 0 while actual possible 1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Answer gives possible 0 while actual possible 1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Answer gives possible 0 while actual possible 1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Answer gives possible 0 while actual possible 1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Answer gives possible 0 while actual possible 1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Answer gives possible 0 while actual possible 1 |
2 | Halted | 0 ms | 0 KB | - |