Submission #301816

#TimeUsernameProblemLanguageResultExecution timeMemory
301816VEGAnnConnecting Supertrees (IOI20_supertrees)C++14
21 / 100
259 ms22264 KiB
#include "supertrees.h"
#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
const int N = 1010;
vector<int> vc;
int pre[N];
int mrk[N];

int get(int x){
    return (pre[x] == x ? x : pre[x] = get(pre[x]));
}

int construct(vector<vector<int>> p) {
	int n = p.size();

    for (int i = 0; i < n; i++)
        pre[i] = i;

    vector<vector<int> > ans;

    ans.resize(n);

    for (int i = 0; i < n; i++)
        ans[i].resize(n);

    for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
        if (p[i][j] > 0){
            int xx = get(i);
            int yy = get(j);

            pre[xx] = yy;
        }

    for (int i = 0; i < n; i++){
        if (mrk[get(i)]) continue;

        mrk[get(i)] = 1;

        vc.clear();

        for (int j = i; j < n; j++)
            if (get(j) == get(i))
                vc.PB(j);

        for (int it = 0; it < sz(vc); it++)
        for (int jt = it + 1; jt < sz(vc); jt++)
            if (p[vc[it]][vc[jt]] == 0)
                return 0;

        for (int it = 0; it < sz(vc); it++){
            if (it > 0) ans[vc[it]][vc[it - 1]] = 1;
            if (it + 1 < sz(vc)) ans[vc[it]][vc[it + 1]] = 1;
        }
    }

	build(ans);

	return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...