제출 #1198970

#제출 시각아이디문제언어결과실행 시간메모리
1198970AMel0n슈퍼트리 잇기 (IOI20_supertrees)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
#define F first 
#define S second

#include "supertrees.h"

vector<int> par;
int find(int n) {
    if (n == par[n]) return par[n];
    return par[n] = find(par[n]);
}
void merge(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return ;
    par[b] = a;
}

int construct(vector<vector<int>> path) {
    int N = path.size();
    par.resize(N);
    iota(all(par), 0);

    FOR(i, N) {
        for (int j = i + 1; j < N; j++) {
            if (path[i][j] > 0) merge(i, j);
        }
    }
    FOR(i, N) {
        for (int j = i + 1; j < N; j++) {
            if (!path[i][j] && find(i) == find(j)) return 0;
        }
    }


    vector<vector<int>> goofy(N);
    FOR(i, N) {
        int parrr = find(i);
        if (i != parrr) goofy[parrr].push_back(i);
    }
    
    vector<vector<int>> res(N, vector<int>(N));
    // FOR(i, N) {
    //     int parrr = find(i);
    //     if (i != parrr) {
    //         res[i][parrr] = 1;
    //         res[parrr][i] = 1;
    //     }
    // }

    FOR(i, N) {
        int pr = -1;
        for(auto v: goofy[i]) {
            if (pr != -1) {
                res[v][pr] = 1;
                res[pr][v] = 1;
            }
            pr = i;
        }
    }
    build(res);
    return 1;
}

// signed main() {
//     cin.tie(0); ios::sync_with_stdio(false);
    
// }
#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...