답안 #657348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
657348 2022-11-09T16:54:07 Z ssense 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
180 ms 24060 KB
#include <bits/stdc++.h>
#include "supertrees.h"
#define startt ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long  ll;
using namespace std;
#define vint vector<int>
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MOD2 998244353
#define MX 1000000000
#define MXL 1000000000000000000
#define PI (ld)2*acos(0.0)
#define pb push_back
#define sc second
#define fr first
#define endl '\n'
#define ld long double
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
int ceildiv(int one, int two) {if (one % two == 0) {return one / two;}else {return one / two + 1;}} int power(int n, int pow, int m) {if (pow == 0) return 1;if (pow % 2 == 0) {ll x = power(n, pow / 2, m);return (x * x) % m;}else return (power(n, pow - 1, m) * n) % m;} int gcd(int a, int b) { if (!b)return a; return gcd(b, a % b);} int factorial(int n, int mod) {if (n > 1)return (n * factorial(n - 1, mod)) % mod; else return 1;} int lcm(int a, int b) {return (a * b) / gcd(a, b);} vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}struct prefix_sum{vint pref;void build(vint a){pref.pb(0);for(int i = 0; i < a.size(); i++){pref.pb(pref.back()+a[i]);}}int get(int l, int r){return pref[r]-pref[l-1];}};//mesanu

int par[1005];
int sz[1005];

void init(int n)
{
    for(int i = 0; i < n; i++)
    {
        par[i] = i;
        sz[i] = 1;
    }
}

int find(int v) {
    if (v == par[v])
        return v;
    return par[v] = find(par[v]);
}

void usets(int a, int b) {
    a = find(a);
    b = find(b);
    if (a != b) {
        if (sz[a] < sz[b])
            swap(a, b);
        par[b] = a;
        sz[a] += sz[b];
    }
}


int construct(vector<vector<int>> p)
{
    int n = (int)p.size();
    init(1000);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(p[i][j] == 1)
            {
                usets(i, j);
            }
            if(p[i][j] == 3)
            {
                return 0;
            }
        }
    }
    vector<int> sets(n);
    for(int i = 0; i < n; i++)
    {
        sets[i] = find(i);
    }
    for(int i = 0; i < n; i++)
    {
        int cnt_2 = 0;
        for(int j = 0; j < n; j++)
        {
            if(p[i][j] == 2)
            {
                cnt_2++;
            }
            if(p[i][i] != 1)
            {
                return 0;
            }
            if(p[i][j] == 0 && sets[i] == sets[j])
            {
                return 0;
            }
            if(p[i][j] == 2 && sets[i] == sets[j])
            {
                return 0;
            }
        }
        if(cnt_2 == 1)
        {
            return 0;
        }
    }
    vector<vector<int>> answer(n, vector<int>(n));
    vector<bool> vis(n, false);
    for(int i = 0; i < n; i++)
    {
        int now = i;
        while(!vis[now])
        {
            vis[now] = true;
            if(now == par[now])
            {
                break;
            }
            answer[now][par[now]] = 1;
            answer[par[now]][now] = 1;
            now = par[now];
        }
    }
    vector<bool> incycle(n, false);
    for(int i = 0; i < n; i++)
    {
        set<int> cycle_now;
        int now = sets[i];
        if(incycle[now])
        {
            continue;
        }
        cycle_now.insert(now);
        incycle[now] = true;
        for(int j = 0; j < n; j++)
        {
            if(p[i][j] == 2)
            {
                cycle_now.insert(sets[j]);
                incycle[sets[j]] = true;
            }
        }
        if(cycle_now.size() > 2)
        {
            auto it = cycle_now.end();
            it--;
            int last = *it;
            for(auto x : cycle_now)
            {
                answer[x][last] = 1;
                answer[last][x] = 1;
                usets(x, last);
                last = x;
            }
        }
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(p[i][j] == 0 && find(i) == find(j))
            {
                return 0;
            }
            if(p[i][j] == 2 && find(i) != find(j))
            {
                return 0;
            }
        }
    }
    build(answer);
    return 1;
}

Compilation message

supertrees.cpp: In member function 'void prefix_sum::build(std::vector<int>)':
supertrees.cpp:20:667: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 | int ceildiv(int one, int two) {if (one % two == 0) {return one / two;}else {return one / two + 1;}} int power(int n, int pow, int m) {if (pow == 0) return 1;if (pow % 2 == 0) {ll x = power(n, pow / 2, m);return (x * x) % m;}else return (power(n, pow - 1, m) * n) % m;} int gcd(int a, int b) { if (!b)return a; return gcd(b, a % b);} int factorial(int n, int mod) {if (n > 1)return (n * factorial(n - 1, mod)) % mod; else return 1;} int lcm(int a, int b) {return (a * b) / gcd(a, b);} vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}struct prefix_sum{vint pref;void build(vint a){pref.pb(0);for(int i = 0; i < a.size(); i++){pref.pb(pref.back()+a[i]);}}int get(int l, int r){return pref[r]-pref[l-1];}};//mesanu
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1180 KB Output is correct
7 Correct 160 ms 22036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1180 KB Output is correct
7 Correct 160 ms 22036 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 166 ms 22080 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 76 ms 8080 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 42 ms 5696 KB Output is correct
21 Correct 168 ms 22024 KB Output is correct
22 Correct 163 ms 21964 KB Output is correct
23 Correct 180 ms 21968 KB Output is correct
24 Correct 163 ms 22020 KB Output is correct
25 Correct 64 ms 8140 KB Output is correct
26 Correct 60 ms 8140 KB Output is correct
27 Correct 176 ms 22064 KB Output is correct
28 Correct 167 ms 22004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1104 KB Output is correct
9 Correct 166 ms 22036 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 166 ms 22064 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 780 KB Output is correct
17 Correct 78 ms 12164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 42 ms 5760 KB Output is correct
22 Correct 167 ms 21964 KB Output is correct
23 Correct 165 ms 22032 KB Output is correct
24 Correct 180 ms 21964 KB Output is correct
25 Correct 68 ms 8068 KB Output is correct
26 Correct 68 ms 12036 KB Output is correct
27 Correct 163 ms 24060 KB Output is correct
28 Correct 177 ms 23984 KB Output is correct
29 Correct 62 ms 10108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 43 ms 5812 KB Output is correct
5 Correct 171 ms 21988 KB Output is correct
6 Correct 164 ms 22060 KB Output is correct
7 Correct 178 ms 22116 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 43 ms 5744 KB Output is correct
10 Correct 168 ms 22020 KB Output is correct
11 Correct 166 ms 21964 KB Output is correct
12 Correct 180 ms 22020 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 42 ms 5772 KB Output is correct
17 Correct 167 ms 22032 KB Output is correct
18 Correct 165 ms 21964 KB Output is correct
19 Correct 162 ms 22032 KB Output is correct
20 Correct 166 ms 21964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1180 KB Output is correct
7 Correct 160 ms 22036 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 166 ms 22080 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 76 ms 8080 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 42 ms 5696 KB Output is correct
21 Correct 168 ms 22024 KB Output is correct
22 Correct 163 ms 21964 KB Output is correct
23 Correct 180 ms 21968 KB Output is correct
24 Correct 163 ms 22020 KB Output is correct
25 Correct 64 ms 8140 KB Output is correct
26 Correct 60 ms 8140 KB Output is correct
27 Correct 176 ms 22064 KB Output is correct
28 Correct 167 ms 22004 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1104 KB Output is correct
37 Correct 166 ms 22036 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1108 KB Output is correct
41 Correct 166 ms 22064 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 780 KB Output is correct
45 Correct 78 ms 12164 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 42 ms 5760 KB Output is correct
50 Correct 167 ms 21964 KB Output is correct
51 Correct 165 ms 22032 KB Output is correct
52 Correct 180 ms 21964 KB Output is correct
53 Correct 68 ms 8068 KB Output is correct
54 Correct 68 ms 12036 KB Output is correct
55 Correct 163 ms 24060 KB Output is correct
56 Correct 177 ms 23984 KB Output is correct
57 Correct 62 ms 10108 KB Output is correct
58 Correct 0 ms 304 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 3 ms 596 KB Output is correct
61 Correct 74 ms 10100 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 308 KB Output is correct
65 Correct 42 ms 6244 KB Output is correct
66 Correct 69 ms 14072 KB Output is correct
67 Correct 63 ms 10104 KB Output is correct
68 Correct 64 ms 14076 KB Output is correct
69 Correct 62 ms 10100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1180 KB Output is correct
7 Correct 160 ms 22036 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 166 ms 22080 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 76 ms 8080 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 42 ms 5696 KB Output is correct
21 Correct 168 ms 22024 KB Output is correct
22 Correct 163 ms 21964 KB Output is correct
23 Correct 180 ms 21968 KB Output is correct
24 Correct 163 ms 22020 KB Output is correct
25 Correct 64 ms 8140 KB Output is correct
26 Correct 60 ms 8140 KB Output is correct
27 Correct 176 ms 22064 KB Output is correct
28 Correct 167 ms 22004 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1104 KB Output is correct
37 Correct 166 ms 22036 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1108 KB Output is correct
41 Correct 166 ms 22064 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 780 KB Output is correct
45 Correct 78 ms 12164 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 42 ms 5760 KB Output is correct
50 Correct 167 ms 21964 KB Output is correct
51 Correct 165 ms 22032 KB Output is correct
52 Correct 180 ms 21964 KB Output is correct
53 Correct 68 ms 8068 KB Output is correct
54 Correct 68 ms 12036 KB Output is correct
55 Correct 163 ms 24060 KB Output is correct
56 Correct 177 ms 23984 KB Output is correct
57 Correct 62 ms 10108 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 43 ms 5812 KB Output is correct
62 Correct 171 ms 21988 KB Output is correct
63 Correct 164 ms 22060 KB Output is correct
64 Correct 178 ms 22116 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 43 ms 5744 KB Output is correct
67 Correct 168 ms 22020 KB Output is correct
68 Correct 166 ms 21964 KB Output is correct
69 Correct 180 ms 22020 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 42 ms 5772 KB Output is correct
74 Correct 167 ms 22032 KB Output is correct
75 Correct 165 ms 21964 KB Output is correct
76 Correct 162 ms 22032 KB Output is correct
77 Correct 166 ms 21964 KB Output is correct
78 Correct 0 ms 304 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 3 ms 596 KB Output is correct
81 Correct 74 ms 10100 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 308 KB Output is correct
85 Correct 42 ms 6244 KB Output is correct
86 Correct 69 ms 14072 KB Output is correct
87 Correct 63 ms 10104 KB Output is correct
88 Correct 64 ms 14076 KB Output is correct
89 Correct 62 ms 10100 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 300 KB Output is correct
92 Correct 3 ms 596 KB Output is correct
93 Correct 68 ms 10104 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 16 ms 2684 KB Output is correct
98 Correct 63 ms 10116 KB Output is correct
99 Correct 66 ms 10120 KB Output is correct
100 Correct 65 ms 10108 KB Output is correct
101 Correct 61 ms 10120 KB Output is correct
102 Correct 64 ms 10104 KB Output is correct
103 Correct 61 ms 10120 KB Output is correct
104 Correct 62 ms 10116 KB Output is correct
105 Correct 72 ms 10108 KB Output is correct