| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 317702 | amunduzbaev | 슈퍼트리 잇기 (IOI20_supertrees) | C++14 | 472 ms | 24312 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 "grader.cpp"
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define pb(a) push_back(a)
const int N=1005;
int used[N];
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int> > b(n);
bool ok1=0, ok2=0, ok0=0;
for(int i=0;i<n;i++){
b[i].assign(n, 0);
for(int j=i+1;j<n;j++){
if(p[i][j] == 1) ok1=1;
else if(p[i][j] == 2) ok2=1;
else if(p[i][j] == 0) ok0=1;
else if(p[i][j] == 3) return 0;
}
}
if(ok1 && !ok2 && !ok0){
for(int i=1;i<n;i++){
b[0][i] = 1;
b[i][0] = 1;
}
build(b);
return 1;
}
else if((ok1 || ok0) && !ok2){
vector<vector<int>> v(n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j] == 1 && i!=j){
v[i].push_back(j);
}
}
for(int j=0;j<v[i].size();j++){
if(!p[v[i][j]][i]) return 0;
for(int l=j;l<v[i].size();l++){
if(!p[v[i][l]][v[i][j]]) return 0;
}
}
}
for(int i=0;i<n;i++){
if(used[i]) continue;
for(int j=0;j<v[i].size();j++){
used[v[i][j]] = 1;
b[i][v[i][j]] = 1;
b[v[i][j]][i] = 1;
}
}
build(b);
return 1;
}
else if((ok2 || ok0) && !ok1){
vector<vector<int>> v(n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
if(p[i][j] == 2 && i!=j)
v[i].push_back(j);
if(v[i].size() == 1) return 0;
for(int j=0;j<v[i].size();j++){
if(!p[v[i][j]][i]) return 0;
for(int l=j+1;l<v[i].size();l++)
if(!p[v[i][l]][v[i][j]]) return 0;
}
}
for(int i=0;i<n;i++){
if(used[i]) continue;
int j=0;
b[i][v[i][j]] = 1;
b[v[i][j]][i] = 1;
for(;j<v[i].size() -1;j++){
used[v[i][j]] = 1;
b[v[i][j]][v[i][j+1]] = 1;
b[v[i][j+1]][v[i][j]] = 1;
}
used[v[i][j]] = 1;
b[i][v[i][j]] = 1;
b[v[i][j]][i] = 1;
}
build(b);
return 1;
}
if(ok0 || ok1 || ok2){
vector<vector<int> > ones(n), twos(n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i!=j && p[i][j] == 1)
ones[i].pb(j);
if(i!=j && p[i][j] == 2)
twos[i].pb(j);
}
}
for(int i=0;i<n;i++){
if(used[i])continue;
for(int j=0;j<ones[i].size();j++){
used[ones[i][j]] = 1;
b[i][ones[i][j]] = 1;
b[ones[i][j]][i] = 1;
}
int j = 0, sz = twos[i].size();
b[i][twos[i][j]] = 1;
b[twos[i][j]][i] = 1;
for(;j<sz-1; j++){
used[twos[i][j]] = 1;
b[twos[i][j]][twos[i][j+1]] = 1;
b[twos[i][j+1]][twos[i][j]] = 1;
//cout<<twos[i][j]<<" ";
}
used[twos[i][j]] = 1;
b[i][twos[i][j]] = 1;
b[twos[i][j]][i] = 1;
}
build(b);
return 1;
}
return 0;
}
/*
5
0 2 2 2 2
2 0 2 2 2
2 2 0 2 2
2 2 2 0 2
2 2 2 2 0
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 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... | ||||
