# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
362807 | mathking1021 | Connecting Supertrees (IOI20_supertrees) | C++17 | 291 ms | 24324 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>
using namespace std;
int cp[1005];
vector<int> ve[1005];
int fnd(int p)
{
if(cp[p] == p) return p;
return cp[p] = fnd(cp[p]);
}
void uni(int p, int q)
{
if(fnd(p) == fnd(q)) return;
cp[fnd(p)] = fnd(q);
}
int construct(vector<vector<int> > p) {
int n = p.size();
vector<vector<int> > answer;
for(int i = 0; i < n; i++)
{
cp[i] = i;
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(p[i][j]) uni(i, j);
}
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(!p[i][j] && fnd(i) == fnd(j)) return 0;
}
}
for(int i = 0; i < n; i++)
{
vector<int> row;
for(int j = 0; j < n; j++)
{
row.push_back(0);
}
answer.push_back(row);
}
for(int i = 0; i < n; i++)
{
ve[fnd(i)].push_back(i);
}
for(int i = 0; i < n; i++)
{
if(ve[i].size() == 2) return 0;
if(ve[i].size() == 0) continue;
if(ve[i].size() == 1) continue;
for(int j = 1; j < ve[i].size(); j++)
{
answer[ve[i][j]][ve[i][j - 1]] = 1;
answer[ve[i][j - 1]][ve[i][j]] = 1;
}
answer[ve[i][0]][ve[i][ve[i].size() - 1]] = 1;
answer[ve[i][ve[i].size() - 1]][ve[i][0]] = 1;
}
build(answer);
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... |