답안 #927340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927340 2024-02-14T18:33:35 Z VMaksimoski008 슈퍼트리 잇기 (IOI20_supertrees) C++14
21 / 100
167 ms 24508 KB
#include <bits/stdc++.h>
#include "supertrees.h"

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;

struct DSU {
    int n, comp;
    vector<int> par, size;

    void config(int _n) {
        n = _n + 1;
        comp = _n;
        par.resize(n+1);
        size.resize(n+1, 1);
        for(int i=1; i<=n; i++) par[i] = i;
    }

    int get(int u) {
        if(u == par[u]) return u;
        return par[u] = get(par[u]);
    }

    bool uni(int u, int v) {
        u = get(u), v = get(v);

        if(u == v) return false;
        if(size[u] < size[v]) swap(u, v);

        size[u] += size[v];
        par[v] = u;
        comp--;

        return true;
    }

    int getComp() { return comp; }
    int getSize(int u) { return size[get(u)]; }
    bool sameSet(int u, int v) { return get(u) == get(v); }
};

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

    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++) cnt[p[i][j]]++;

    if(cnt[0] + cnt[1] == n*n) {
        DSU dsu; dsu.config(n);
        vector<vector<int> > B(n, vector<int>(n, 0));

        for(int i=0; i<n; i++) {
            for(int j=0; j<n; j++) {
                if(p[i][j] == 1)
                    if(dsu.uni(i, j)) B[i][j] = B[j][i] = 1;
            }
        }

        for(int i=0; i<n; i++) {
            for(int j=0; j<n; j++) {
                if(p[i][j] == 1 && !dsu.sameSet(i, j)) return 0;
                if(p[i][j] == 0 && dsu.sameSet(i, j)) return 0;
            }
        }

        build(B);
        return 1;
    } else {
        DSU dsu, dsu2;
        dsu.config(n), dsu2.config(n);
        vector<vector<int> > B(n, vector<int>(n, 0));

        for(int i=0; i<n; i++) {
            for(int j=0; j<n; j++) {
                if(p[i][j] == 1) {
                    if(!dsu.sameSet(i, j)) {
                        dsu.uni(i, j);
                        B[i][j] = B[j][i] = 1;
                    }
                } else if(p[i][j] == 2) {
                    if(!dsu.sameSet(i, j) && !dsu2.sameSet(i, j)) {
                        dsu.uni(i, j);
                        B[i][j] = B[j][i] = 1;
                    } else if(dsu.sameSet(i, j) && !dsu2.sameSet(i, j)) {
                        dsu2.uni(i, j);
                        B[i][j] = B[j][i] = 1;
                    }
                }
            }
        }
        
        build(B);
        return 1;
    }

    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 160 ms 24092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 160 ms 24092 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 436 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 156 ms 23980 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 77 ms 13996 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 40 ms 6232 KB Output is correct
21 Correct 157 ms 24148 KB Output is correct
22 Correct 154 ms 24004 KB Output is correct
23 Correct 167 ms 24076 KB Output is correct
24 Correct 154 ms 24508 KB Output is correct
25 Correct 68 ms 14164 KB Output is correct
26 Correct 66 ms 14084 KB Output is correct
27 Correct 161 ms 24144 KB Output is correct
28 Correct 155 ms 24144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 42 ms 6228 KB Output is correct
5 Correct 160 ms 23888 KB Output is correct
6 Correct 153 ms 23936 KB Output is correct
7 Correct 161 ms 23888 KB Output is correct
8 Incorrect 0 ms 348 KB Too many ways to get from 0 to 3, should be 2 found no less than 3
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 160 ms 24092 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 436 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 156 ms 23980 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 77 ms 13996 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 40 ms 6232 KB Output is correct
21 Correct 157 ms 24148 KB Output is correct
22 Correct 154 ms 24004 KB Output is correct
23 Correct 167 ms 24076 KB Output is correct
24 Correct 154 ms 24508 KB Output is correct
25 Correct 68 ms 14164 KB Output is correct
26 Correct 66 ms 14084 KB Output is correct
27 Correct 161 ms 24144 KB Output is correct
28 Correct 155 ms 24144 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 160 ms 24092 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 436 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 156 ms 23980 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 77 ms 13996 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 40 ms 6232 KB Output is correct
21 Correct 157 ms 24148 KB Output is correct
22 Correct 154 ms 24004 KB Output is correct
23 Correct 167 ms 24076 KB Output is correct
24 Correct 154 ms 24508 KB Output is correct
25 Correct 68 ms 14164 KB Output is correct
26 Correct 66 ms 14084 KB Output is correct
27 Correct 161 ms 24144 KB Output is correct
28 Correct 155 ms 24144 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -