# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
318355 | NintsiChkhaidze | Connecting Supertrees (IOI20_supertrees) | C++14 | 274 ms | 22244 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 <iostream>
#include <vector>
#define pb push_back
using namespace std;
vector<vector<int>> answer;
vector <int> row,cycle;
int par[1005];
bool f[1005];
int construct(vector<vector<int>> p) {
int n = p.size(),a=0,b=0;
for(int i=0;i<n;i++){
row.clear();
for (int j=0;j<n;j++){
if (p[i][j] == 2) a=1;
if (p[i][j] == 1 && i!=j) b=1;
if (p[i][j] == 3) return 0;
if (p[i][i] != 1) return 0;
row.pb(0);
}
answer.pb(row);
}
for(int i=0;i<n;i++)
par[i]=i;
for (int i=0;i<n;i++){
if (f[i]) continue;
for (int j=0;j<n;j++){
if (p[i][j] == 1 && i!=j){
f[j]=1;
par[j] = i;
answer[i][j]=answer[j][i]=1;
}
}
}
for(int i=0;i<n;i++) f[i]=0;
if (a == 0){
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
if (par[i] == par[j] && p[i][j] != 1) return 0;
if (par[i] != par[j] && p[i][j] != 0) return 0;
}
}
}
for(int i=0;i<n;i++){
if (f[i]) continue;
row.clear();
for (int j=0;j<n;j++)
if (p[i][j] == 2) f[j] = 1,row.pb(j);
int cur = i;
cycle.clear();
cycle.pb(i);
par[i] = i;
for (int j=0;j<row.size();j++){
cycle.pb(row[j]);
par[row[j]] = i;
answer[row[j]][cur] = answer[cur][row[j]] = 1;
cur = row[j];
}
if (row.size()==0) continue;
if (row.size() == 1) {return 0;}
answer[i][cur] = answer[cur][i] = 1;
}
if (a==1 && b==0){
for (int i=0;i<n;i++)
for (int j=i+1;j<n;j++){
if (par[i] == par[j] && p[i][j]!=2) return 0;
if (par[i]!=par[j] && p[i][j]!=0) return 0;
}
}
build(answer);
return 1;
}
/*
6
1 2 2 0 0 0
2 1 2 0 0 0
2 2 1 0 0 0
0 0 0 1 2 2
0 0 0 2 1 2
0 0 0 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... |