# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
589632 | LIF | Connecting Supertrees (IOI20_supertrees) | C++14 | 222 ms | 27928 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;
int checkx[1005][1005];
int f[1005];
int find(int x)
{
if(f[x] == x)
{
return x;
}
return f[x] = find(f[x]);
}
int construct(std::vector<std::vector <int> > p) {
int n = p[0].size();
for(int i=0;i<n;i++)
{
f[i] = i;
}
bool flag = 1;
bool flagk = 1;
vector <vector<int> > ans;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(p[i][j] == 3)
{
return 0;
}
if(p[i][j]!=1)
{
flag = 0;
}
if(p[i][j] !=0&&p[i][j]!=1)
{
flagk = 0;
}
}
}
if(flag == 1) //that means all distance is 1;
{
for(int i=0;i<p[0].size()-1;i++)
{
checkx[i][i+1] = true;
checkx[i+1][i] = true;
}
}
else
{
if(flagk == 1)//that means all distance is 0 or 1;
{
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(find(i)!=find(j))
{
if(p[i][j] == 1)
{
int xx = find(i);
for(int kk=0;kk<n;kk++)
{
if(find(kk) == xx) //that means they are in the same group
{
if(p[xx][j]==0) //that means they can't go to each other,however their father can go to each other.it can't be implented
{
return 0;
break;
}
}
}
//if it hasn't return,that means it can be implented.
checkx[i][j] = true;
checkx[j][i] = true;
//and we should add the j in the same group;
f[find(j)] = find(i);
}
else
{
continue;
}
}
else//that means they are in the same set.
{
if(p[i][j] == 1)
{
continue;
}
else
{
if(p[i][j] == 0)
{
return 0;
break;
}
}
}
}
}
}
}
for(int i=0;i<p[0].size();i++)
{
vector<int> v;
for(int j=0;j<p[0].size();j++)
{
if(i==j)
{
v.push_back(0);
}
else
{
if(checkx[i][j] == true)
{
v.push_back(1);
}
else
{
v.push_back(0);
}
}
}
ans.push_back(v);
}
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... |