# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303871 | kjain_1810 | Connecting Supertrees (IOI20_supertrees) | C++17 | 1 ms | 384 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<stdio.h>
#define pb push_back
const int N = 1005;
using namespace std;
int taken[N], compcnt = 1, n;
vector<int>comp[N];
bool checkValid(vector<vector<int>>p)
{
for(int a = 1; a < compcnt; a++)
for(int b = 0; b < comp[a].size(); b++)
for(int c = 0; c < comp[a].size(); c++)
if(!p[comp[a][b]][comp[a][c]] || p[a][b] == 3)
return false;
for(int a = 0; a < n; a++)
for(int b = 0; b < n; b++)
if(p[a][b] && taken[a] != taken[b])
return false;
return true;
}
int gettype(vector<int>component, vector<vector<int>>p)
{
int mini = 3;
int maxi = 0;
for(auto a:component)
for(auto b:component)
{
mini=min(mini, p[a][b]);
maxi=max(maxi, p[a][b]);
}
if(mini == maxi)
{
if(mini == 1)
return 0;
else
return 1;
}
return 2;
}
int construct(vector<vector<int>> p) {
n = p.size();
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
answer.push_back(row);
}
// printf("1\n");
for(int a = 0; a < n; a++)
{
if(taken[a])
continue;
for(int b = 0; b < n; b++)
if(p[a][b])
{
// printf("%d ", b);
comp[compcnt].pb(b);
taken[b] = compcnt;
}
// printf("\n");
compcnt++;
}
// printf("2\n");
if(!checkValid(p))
return 0;
// printf("3\n");
for(int i = 1; i < compcnt; i++)
{
int x = gettype(comp[i], p);
// printf("4\n");
if(x == 0)
{
for(int a = 1; a < comp[i].size(); a++)
answer[comp[i][a]][comp[i][a - 1]] = answer[comp[i][a - 1]][comp[i][a]] = 1;
}
else if(x == 1)
{
for(int a = 1; a < comp[i].size(); a++)
answer[comp[i][a]][comp[i][a - 1]] = answer[comp[i][a - 1]][comp[i][a]] = 1;
answer[comp[i][comp[i].size() - 1]][0] = answer[comp[i][0]][comp[i][comp[i].size() - 1]] = 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... |