# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
300281 | aljasdlas | Connecting Supertrees (IOI20_supertrees) | C++14 | 279 ms | 30200 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;
bool possible = true;
vector<vector<int>> b;
int n;
bitset<1005> vis;
bitset<1005> isOne;
vector<int> AdjList[1005];
vector<vector<int>> components;
int compNum[1005];
vector<vector<int>> p;
void dfs(int u) {
// << u << " ";
vis[u] = 1;
compNum[u] = components.size();
components.back().push_back(u);
for(auto &v: AdjList[u])
if(!vis[v])
dfs(v);
}
int construct(vector<vector<int>> p_) {
p = p_;
n = p.size();
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(p[i][j] != 0)
AdjList[i].push_back(j);
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
b.push_back(row);
}
vis.reset();
for(int i = 0; i < n; i++)
if(!vis[i]) {
components.push_back(vector<int>(0));
// << "Comp " << components.size() << ": ";
dfs(i);
// << endl;
}
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(compNum[i] == compNum[j] && p[i][j] == 0)
return 0;
else if(compNum[i] != compNum[j] && p[i][j] > 0)
return 0;
for(auto &v: components) {
isOne.reset();
if(v.size() == 1)
continue;
for(auto &x: v) {
for(auto &y: v) {
if(x == y) continue;
if(p[x][y] == 1)
isOne[x]=isOne[y]=1;
}
}
for(auto &x: v) {
for(auto &y: v) {
if(x == y) continue;
if(isOne[x]) {
if(isOne[y]) {
if(p[x][y] != 1) return 0;
}
}
}
}
vector<int> is[3];
for(auto &x: v)
if(isOne[x]) is[1].push_back(x);
else is[2].push_back(x);
// << "Is 1: "; for(auto x: is[1]) cerr << x << " "; cerr << endl;
// << "Is 2: "; for(auto x: is[2]) cerr << x << " "; cerr << endl;
if(is[2].size() == 1) return 0;
if(is[2].size() == 0) {
for(int i = 1; i < is[1].size(); i++) {
b[is[1][i-1]][is[1][i]] = 1;
b[is[1][i]][is[1][i-1]] = 1;
}
} else if(is[1].size() == 0) {
for(int i = 1; i < is[2].size(); i++) {
b[is[2][i-1]][is[2][i]] = 1;
b[is[2][i]][is[2][i-1]] = 1;
}
b[is[2][is[2].size()-1]][is[2][0]] = 1;
b[is[2][0]][is[2][is[2].size()-1]] = 1;
if(is[2].size() == 2) return 0;
} else {
for(int i = 1; i < is[1].size(); i++) {
b[is[1][i-1]][is[1][i]] = 1;
b[is[1][i]][is[1][i-1]] = 1;
}
for(int i = 1; i < is[2].size(); i++) {
b[is[2][i-1]][is[2][i]] = 1;
b[is[2][i]][is[2][i-1]] = 1;
}
b[is[2][0]][is[1][is[1].size()-1]] = 1;
b[is[1][is[1].size()-1]][is[2][0]] = 1;
b[is[2][is[2].size()-1]][is[1][is[1].size()-1]] = 1;
b[is[1][is[1].size()-1]][is[2][is[2].size()-1]] = 1;
}
}
if(!possible)
return 0;
build(b);
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... |