답안 #1073186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073186 2024-08-24T10:06:49 Z TheQuantiX 슈퍼트리 잇기 (IOI20_supertrees) C++17
21 / 100
204 ms 22300 KB
#include <bits/stdc++.h>
#include "supertrees.h"
 
using namespace std;
using ll = long long;
 
ll n, m, q, k, x, y, a, b, c;
 
struct dsu {
    ll n;
    vector<ll> par;
    vector<ll> sz;
 
    dsu(ll N) : n(N) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            sz[i] = 1;
        }
    }
 
    ll find_p(ll x) {
        if (par[x] == x) {
            return x;
        }
        ll p = find_p(par[x]);
        par[x] = p;
        return p;
    }
 
    void join(ll x, ll y) {
        x = find_p(x);
        y = find_p(y);
        if (x == y) {
            return;
        }
        if (sz[y] > sz[x]) {
            swap(x, y);
        }
        par[y] = x;
        sz[x] += sz[y];
    }
};
 
int construct(vector< vector<int> > p) {
    n = p.size();
    vector< vector<int> > ans(n, vector<int>(n));
    vector< vector<ll> > comp(n);
    vector< vector<ll> > comp2(n);
    dsu d(n);
    bitset<1000> bt;
    for (int i = 0; i < n; i++) {
        if (p[i][i] != 1) {
            return 0;
        }
        for (int j = 0; j < i; j++) {
            if (p[i][j] == 1) {
                d.join(i, j);
                bt.set(i);
                bt.set(j);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (!bt[i]) {
            continue;
        }
        comp[d.find_p(i)].push_back(i);
    }
    for (auto i : comp) {
        for (int j : i) {
            for (int k : i) {
                if (p[j][k] != 1) {
                    return 0;
                }
            }
        }
    }
    for (auto i : comp) {
        if (i.size() <= 1) {
            continue;
        }
        for (int j = 0; j < i.size() - 1; j++) {
            ans[i[(j + 1) % i.size()]][i[j]] = 1;
            ans[i[j]][i[(j + 1) % i.size()]] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        set<ll> st2;
        for (int j : comp[i]) {
            for (int k = 0; k < n; k++) {
                if (p[j][k] == 2) {
                    // if (bt[k]) {
                    //     return 0;
                    // }
                    st2.insert(k);
                }
            }
        }
        // cout << i << ' ' << st2.size() << '\n';
        for (int j : st2) {
            comp2[i].push_back(j);
            bt.set(j);
        }
    }
    // for (auto i : comp2) {
    //     if (i.size() == 1) {
    //         return 0;
    //     }
    //     for (int j : i) {
    //         for (int k : i) {
    //             if (j != k && p[j][k] != 2) {
    //                 return 0;
    //             }
    //         }
    //     }
    // }
    // for (auto i = 0; i < n; i++) {
    //     for (int j : comp[i]) {
    //         for (int k : comp2[i]) {
    //             if (p[j][k] != 2) {
    //                 return 0;
    //             }
    //         }
    //     }
    // }
    // cout << "DEBUG" << endl;
    for (auto i = 0; i < n; i++) {
        if (comp2[i].size() == 0) {
            continue;
        }
        comp2[i].push_back(i);
        for (int j = 0; j < comp2[i].size(); j++) {
            ans[comp2[i][(j + 1) % comp2[i].size()]][comp2[i][j]] = 1;
            ans[comp2[i][j]][comp2[i][(j + 1) % comp2[i].size()]] = 1;
        }
    }
    vector< vector<ll> > comp2i(n);
    bitset<1000> bt2;
    dsu d2(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            // if (bt[i] && !bt[j] && p[i][j] != 0) {
            //     return 0;
            // }
            // if (!bt[i] && bt[j] && p[i][j] != 0) {
            //     return 0;
            // }
            if (!bt[i] && !bt[j] && p[i][j] == 2) {
                d2.join(i, j);
                bt2.set(i);
                bt2.set(j);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (bt2[i]) {
            comp2i[d2.find_p(i)].push_back(i);
        }
    }
    // for (auto i : comp2i) {
    //     if (i.size() == 2) {
    //         return 0;
    //     }
    //     for (int j : i) {
    //         for (int k : i) {
    //             if (j != k && p[j][k] != 2) {
    //                 return 0;
    //             }
    //         }
    //     }
    // }
    for (auto i : comp2i) {
        if (i.size() <= 1) {
            continue;
        }
        for (int j = 0; j < i.size(); j++) {
            ans[i[(j + 1) % i.size()]][i[j]] = 1;
            ans[i[j]][i[(j + 1) % i.size()]] = 1;
        }
    }
    build(ans);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:84:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |         for (int j = 0; j < i.size() - 1; j++) {
      |                         ~~^~~~~~~~~~~~~~
supertrees.cpp:134:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  134 |         for (int j = 0; j < comp2[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:178:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  178 |         for (int j = 0; j < i.size(); j++) {
      |                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 11 ms 1112 KB Output is correct
7 Correct 204 ms 22300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 11 ms 1112 KB Output is correct
7 Correct 204 ms 22300 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1104 KB Output is correct
13 Correct 141 ms 22284 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 73 ms 12292 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 33 ms 5748 KB Output is correct
21 Correct 156 ms 22296 KB Output is correct
22 Correct 141 ms 22100 KB Output is correct
23 Correct 128 ms 22096 KB Output is correct
24 Correct 163 ms 22040 KB Output is correct
25 Correct 54 ms 12116 KB Output is correct
26 Correct 71 ms 12116 KB Output is correct
27 Correct 153 ms 22096 KB Output is correct
28 Correct 134 ms 22096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 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 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 60 ms 5716 KB Output is correct
5 Correct 128 ms 22100 KB Output is correct
6 Correct 164 ms 22280 KB Output is correct
7 Correct 128 ms 22292 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 32 ms 5772 KB Output is correct
10 Correct 175 ms 22096 KB Output is correct
11 Correct 193 ms 22296 KB Output is correct
12 Correct 124 ms 22100 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 29 ms 5980 KB Too many ways to get from 0 to 463, should be 2 found no less than 3
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 11 ms 1112 KB Output is correct
7 Correct 204 ms 22300 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1104 KB Output is correct
13 Correct 141 ms 22284 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 73 ms 12292 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 33 ms 5748 KB Output is correct
21 Correct 156 ms 22296 KB Output is correct
22 Correct 141 ms 22100 KB Output is correct
23 Correct 128 ms 22096 KB Output is correct
24 Correct 163 ms 22040 KB Output is correct
25 Correct 54 ms 12116 KB Output is correct
26 Correct 71 ms 12116 KB Output is correct
27 Correct 153 ms 22096 KB Output is correct
28 Correct 134 ms 22096 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 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 344 KB Output is correct
2 Correct 1 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 11 ms 1112 KB Output is correct
7 Correct 204 ms 22300 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1104 KB Output is correct
13 Correct 141 ms 22284 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 73 ms 12292 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 33 ms 5748 KB Output is correct
21 Correct 156 ms 22296 KB Output is correct
22 Correct 141 ms 22100 KB Output is correct
23 Correct 128 ms 22096 KB Output is correct
24 Correct 163 ms 22040 KB Output is correct
25 Correct 54 ms 12116 KB Output is correct
26 Correct 71 ms 12116 KB Output is correct
27 Correct 153 ms 22096 KB Output is correct
28 Correct 134 ms 22096 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -