# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
300293 | aljasdlas | Connecting Supertrees (IOI20_supertrees) | C++14 | 254 ms | 26360 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> onevis;
bitset<1005> isOne;
vector<vector<int>> components;
int compNum[1005];
vector<vector<int>> onecomponents;
int onecompNum[1005];
vector<vector<int>> p;
void dfs(int u) {
// << u << " ";
vis[u] = 1;
compNum[u] = components.size();
components.back().push_back(u);
for(int v = 0; v < n; v++)
if(!vis[v] && p[u][v])
dfs(v);
}
void onedfs(int u) {
onevis[u] = 1;
onecompNum[u] = onecomponents.size();
onecomponents.back().push_back(u);
for(int v = 0; v < n; v++)
if(!onevis[v] && p[u][v] == 1)
onedfs(v);
}
int construct(vector<vector<int>> p_) {
p = p_;
n = p.size();
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++) {
if(!onevis[i]) {
onecomponents.push_back(vector<int>(0));
// << "Comp " << components.size() << ": ";
onedfs(i);
// << endl;
if(onecomponents.back().size() == 1) {
onecompNum[i] = 0;
onecomponents.pop_back();
}
}
}
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++) {
if(p[i][j] == 3) return 0;
if(compNum[i] == compNum[j] && p[i][j] == 0)
return 0;
else if(compNum[i] != compNum[j] && p[i][j] > 0)
return 0;
if(onecompNum[i] == onecompNum[j] && onecompNum[i] != 0 && p[i][i] != 1)
return 0;
}
for(auto &v: components) {
isOne.reset();
if(v.size() == 1)
continue;
vector<int> is[3];
for(auto &x: v)
if(onecompNum[x] == 0) is[2].push_back(x);
for(auto &x: v) {
if(onecompNum[x] > 0) {
auto &w = onecomponents[onecompNum[x]-1];
for(int i = 0; i+1 < w.size(); i++) {
b[w[i]][w[i+1]] = 1;
b[w[i+1]][w[i]] = 1;
}
is[2].push_back(w.back());
for(auto y: w)
onecompNum[y] = -1;
}
}
// << "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() == 2) return 0;
if(is[2].size() > 2) {
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(!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... |