# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
790199 | Andrey | Connecting Supertrees (IOI20_supertrees) | C++14 | 151 ms | 26024 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 <vector>
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> ans(0);
vector<vector<int>> haha(0);
vector<bool> bruh(3001,true);
int n;
vector<int> col(3000,-1);
vector<int> no(3000,-1);
void dfs(int a, int c) {
col[a] = c;
if(a != c) {
ans[a][c] = 1;
ans[c][a] = 1;
}
for(int i = 0; i < n; i++) {
if(col[i] == -1 && haha[a][i] == 1) {
dfs(i,c);
}
}
}
int construct(vector<vector<int>> p) {
n = p[0].size();
haha = p;
vector<int> wut(0);
for(int i = 0; i < n; i++) {
ans.push_back(vector<int> (n));
}
for(int i = 0; i < n; i++) {
if(col[i] == -1) {
dfs(i,i);
wut.push_back(i);
}
}
for(int i = 0; i < wut.size(); i++) {
if(no[i] == -1) {
vector<int> wow(0);
wow.push_back(wut[i]);
no[i] = i;
for(int j = 0; j < wut.size(); j++) {
if(haha[wut[i]][wut[j]] == 2 && no[j] == -1) {
bruh[j] = false;
wow.push_back(wut[j]);
no[j] = i;
}
}
/* if(wow.size() == 2) {
return 0;
}*/
if(wow.size() > 1) {
for(int j = 0; j < wow.size(); j++) {
ans[wow[j]][wow[(j+1)%(int)wow.size()]] = 1;
ans[wow[(j+1)%(int)wow.size()]][wow[j]] = 1;
}
}
}
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(i != j) {
if((col[i] == col[j]) && haha[i][j] != 1) {
return 0;
}
if((col[i] != col[j] && no[col[i]] == no[col[j]]) && haha[i][j] != 2) {
return 0;
}
if(no[col[i]] != no[col[j]] && haha[i][j] != 0) {
return 0;
}
}
}
}
build(ans);
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... |