답안 #976120

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976120 2024-05-06T07:53:09 Z efedmrlr 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
178 ms 22400 KB
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,popcnt")
#include <bits/stdc++.h>
#include "supertrees.h"


#define lli long long int
#define ld long double
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end();
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define MP make_pair

using namespace std;

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N = 1e5 + 5;
const int INF = 1e9 + 500;
const int MOD = 1e9 + 7;

struct DSU {
    vector<int> p, sz, typ;
    int n;
    void make_set(int x) {
        p[x] = x;
        sz[x] = 1;
    }
    void init(int nn) {
        n = nn;
        p.assign(n + 3, 0);
        sz.assign(n + 3, 0);
        typ.assign(n + 3, 0);
        for(int i = 0; i < n; i++) {
            make_set(i);
        }
    }
    int find_set(int x) {
        return (x == p[x]) ? x : p[x] = find_set(p[x]);
    }
    bool union_set(int x, int y) {
        x = find_set(x); y = find_set(y);
        if(x == y) return 0;
        if(sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        p[y] = x;
        return 1;
    }
};

int construct(std::vector<std::vector<int>> p) {
	int n = (int)p.size();
	vector<vector<int> > ans(n, vector<int>(n, 0));
    DSU ds, ds2;
    ds.init(n);

    // check zero
    bool f = 1;
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(p[i][j]) {
                ds.union_set(i, j);
            }
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(!p[i][j] && ds.find_set(i) == ds.find_set(j)) {
                f = 0;
            }
        }
    }
    if(!f) return 0;
    // cerr << "zort" << endl;
    ds.init(n);
    
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(p[i][j] == 1) {
                ds.union_set(i, j);
            }
        }
    }
    for(int i = 0; i < n; i++) {
        if(ds.sz[ds.find_set(i)] > 1) {
            ds.typ[i] = 1; 
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(p[i][j] == 2 && !ds.typ[i] && !ds.typ[j]) {
                ds.union_set(i, j);
            }
        }
    }
    vector<vector<int> > comp(n, vector<int>());
    for(int i = 0; i < n; i++) {
        comp[ds.find_set(i)].pb(i);
    }
    
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(ds.find_set(i) != i || ds.find_set(j) != j) continue;
            
            if(ds.typ[i] == ds.typ[j]) continue;
            if(p[i][j] != 2) continue; 
            int x = i, y = j;
            if(ds.typ[x]) swap(x, y);
            comp[x].pb(y); 
        } 
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < (int)comp[i].size() - 1; j++) {
            ans[comp[i][j]][comp[i][j + 1]] = 1;
            ans[comp[i][j + 1]][comp[i][j]] = 1;
        }
        if((int)comp[i].size() > 1 && !ds.typ[i]) {
            ans[comp[i].back()][comp[i][0]] = 1;
            ans[comp[i][0]][comp[i].back()] = 1;
        }
    }
    if(!f) return 0;
    build(ans);

	return 1;
}
# 결과 실행 시간 메모리 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 8 ms 1116 KB Output is correct
7 Correct 156 ms 22020 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 8 ms 1116 KB Output is correct
7 Correct 156 ms 22020 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 166 ms 22004 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 69 ms 12056 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 39 ms 5968 KB Output is correct
21 Correct 153 ms 21984 KB Output is correct
22 Correct 150 ms 22024 KB Output is correct
23 Correct 160 ms 22028 KB Output is correct
24 Correct 155 ms 22028 KB Output is correct
25 Correct 68 ms 12052 KB Output is correct
26 Correct 60 ms 12036 KB Output is correct
27 Correct 158 ms 22028 KB Output is correct
28 Correct 170 ms 22024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 512 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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 39 ms 5904 KB Output is correct
5 Correct 158 ms 22044 KB Output is correct
6 Correct 153 ms 22284 KB Output is correct
7 Correct 160 ms 22204 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 38 ms 5724 KB Output is correct
10 Correct 161 ms 22152 KB Output is correct
11 Correct 149 ms 22096 KB Output is correct
12 Correct 178 ms 22400 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Incorrect 39 ms 5724 KB Too few ways to get from 0 to 24, should be 2 found 0
17 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 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 8 ms 1116 KB Output is correct
7 Correct 156 ms 22020 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 166 ms 22004 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 69 ms 12056 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 39 ms 5968 KB Output is correct
21 Correct 153 ms 21984 KB Output is correct
22 Correct 150 ms 22024 KB Output is correct
23 Correct 160 ms 22028 KB Output is correct
24 Correct 155 ms 22028 KB Output is correct
25 Correct 68 ms 12052 KB Output is correct
26 Correct 60 ms 12036 KB Output is correct
27 Correct 158 ms 22028 KB Output is correct
28 Correct 170 ms 22024 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 512 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 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 8 ms 1116 KB Output is correct
7 Correct 156 ms 22020 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 166 ms 22004 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 69 ms 12056 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 39 ms 5968 KB Output is correct
21 Correct 153 ms 21984 KB Output is correct
22 Correct 150 ms 22024 KB Output is correct
23 Correct 160 ms 22028 KB Output is correct
24 Correct 155 ms 22028 KB Output is correct
25 Correct 68 ms 12052 KB Output is correct
26 Correct 60 ms 12036 KB Output is correct
27 Correct 158 ms 22028 KB Output is correct
28 Correct 170 ms 22024 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 512 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -