답안 #543423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
543423 2022-03-30T14:15:18 Z Ronin13 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
190 ms 24116 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
int construct(std::vector<std::vector<int>> p) {
    int n = p.size();
    int lead[n];
    for(int i = 0; i < n; i++){
        lead[i] = i;
    }
    for(int i = 0; i < n; i++){
        if(p[i][i] != 1)return 0;
        for(int j = 0; j < n; j++){
            if(p[i][j] != p[j][i]) return 0;
            if(p[j][i] == 3)return 0;
        }
    }
    vector< vector <int> > ch(n + 1);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < i; j++){
            if( p[i][j]  ){
                if(lead[i] != lead[j] && (lead[i] < i || lead[j] != j) )return 0;
                lead[i] = lead[j];
            }
            if((!p[i][j]) && lead[i] == lead[j])return 0;
        }
        ch[lead[i]].pb(i);
    }
    vector< vector<int> > cmp;
    for(int i = 0; i < n; i++){
        if(!ch[i].empty())cmp.pb(ch[i]);
    }
    for(int i = 0; i < n; i++){
        lead[i] = i;
    }
    vector < vector <int> > ans;
    ans.resize(n);
    for(int i = 0; i < n; i++){
        ans[i].resize(n);
    }
    vector<vector<int> > cur1;
    cur1.resize(n);
    for(vector<int> &cur : cmp){
        for(int to: cur){
            for(int i = 0; i < to; i++){
                if(p[to][i] == 1){
                    if(lead[to] != lead[i] && (lead[to] < to || lead[i] != i) )return 0;
                    else lead[to] = lead[i];
                }
                if(p[to][i] == 2){
                    if(lead[to] == lead[i])return 0;
                }
            }
            cur1[lead[to]].pb(to);
        }
        vector<int>vv;
        for(int to : cur){
           // cout << to << ' ';
            if(cur1[to].size() == 0)continue;
            for(int i = 0; i < cur1[to].size() - 1; i++){
                //if(i == 0)vv.pb(cur1[to][i]);
               // cout << cur1[to][i] << ' ';
                int x = cur1[to][i];
                int y = cur1[to][i + 1];
                ans[x][y] = ans[y][x] = 1;
            }
            vv.pb(cur1[to][0]);
        }
        if(vv.size() == 2)return 0;
        if(vv.size() <= 1)continue;
        for(int i = 0; i < vv.size() - 1; i++){
            int x = vv[i];
            int y = vv[i + 1];
           // cout << x << ' ' << y << "\n";
            ans[x][y] = ans[y][x] = 1;
        }
        int x = vv.back();
       // cout << x;
        int y = vv[0];
        ans[x][y] = ans[y][x] = 1;
    }
    /*for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cout << ans[i][j] << " ";
        }
        cout << "\n";
    }*/
    build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:67:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |             for(int i = 0; i < cur1[to].size() - 1; i++){
      |                            ~~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:78:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for(int i = 0; i < vv.size() - 1; i++){
      |                        ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 8 ms 1156 KB Output is correct
7 Correct 174 ms 22044 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 8 ms 1156 KB Output is correct
7 Correct 174 ms 22044 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 1148 KB Output is correct
13 Correct 165 ms 22160 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 77 ms 8208 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 44 ms 6220 KB Output is correct
21 Correct 172 ms 24060 KB Output is correct
22 Correct 170 ms 24048 KB Output is correct
23 Correct 190 ms 24064 KB Output is correct
24 Correct 171 ms 24064 KB Output is correct
25 Correct 71 ms 10100 KB Output is correct
26 Correct 72 ms 10104 KB Output is correct
27 Correct 176 ms 24116 KB Output is correct
28 Correct 166 ms 24044 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 0 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 1 ms 212 KB Output is correct
8 Correct 7 ms 1108 KB Output is correct
9 Correct 175 ms 22188 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1108 KB Output is correct
13 Correct 164 ms 22028 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 74 ms 8192 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 44 ms 5724 KB Output is correct
22 Correct 172 ms 22092 KB Output is correct
23 Correct 167 ms 22136 KB Output is correct
24 Correct 175 ms 22020 KB Output is correct
25 Correct 70 ms 12236 KB Output is correct
26 Correct 70 ms 8192 KB Output is correct
27 Correct 173 ms 22088 KB Output is correct
28 Correct 173 ms 22116 KB Output is correct
29 Correct 75 ms 12288 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 43 ms 5768 KB Output is correct
5 Correct 166 ms 22152 KB Output is correct
6 Correct 174 ms 22028 KB Output is correct
7 Correct 175 ms 22092 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 44 ms 5724 KB Output is correct
10 Correct 168 ms 22032 KB Output is correct
11 Correct 166 ms 22144 KB Output is correct
12 Correct 180 ms 22020 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 42 ms 5740 KB Output is correct
17 Correct 172 ms 22024 KB Output is correct
18 Correct 171 ms 22160 KB Output is correct
19 Correct 167 ms 22156 KB Output is correct
20 Correct 168 ms 22092 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 8 ms 1156 KB Output is correct
7 Correct 174 ms 22044 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 1148 KB Output is correct
13 Correct 165 ms 22160 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 77 ms 8208 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 44 ms 6220 KB Output is correct
21 Correct 172 ms 24060 KB Output is correct
22 Correct 170 ms 24048 KB Output is correct
23 Correct 190 ms 24064 KB Output is correct
24 Correct 171 ms 24064 KB Output is correct
25 Correct 71 ms 10100 KB Output is correct
26 Correct 72 ms 10104 KB Output is correct
27 Correct 176 ms 24116 KB Output is correct
28 Correct 166 ms 24044 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 0 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 1 ms 212 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 175 ms 22188 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1108 KB Output is correct
41 Correct 164 ms 22028 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 596 KB Output is correct
45 Correct 74 ms 8192 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 44 ms 5724 KB Output is correct
50 Correct 172 ms 22092 KB Output is correct
51 Correct 167 ms 22136 KB Output is correct
52 Correct 175 ms 22020 KB Output is correct
53 Correct 70 ms 12236 KB Output is correct
54 Correct 70 ms 8192 KB Output is correct
55 Correct 173 ms 22088 KB Output is correct
56 Correct 173 ms 22116 KB Output is correct
57 Correct 75 ms 12288 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 3 ms 596 KB Output is correct
61 Correct 77 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 296 KB Output is correct
65 Correct 44 ms 6256 KB Output is correct
66 Correct 70 ms 10096 KB Output is correct
67 Correct 73 ms 10096 KB Output is correct
68 Correct 71 ms 10060 KB Output is correct
69 Correct 73 ms 14196 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 8 ms 1156 KB Output is correct
7 Correct 174 ms 22044 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 1148 KB Output is correct
13 Correct 165 ms 22160 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 77 ms 8208 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 44 ms 6220 KB Output is correct
21 Correct 172 ms 24060 KB Output is correct
22 Correct 170 ms 24048 KB Output is correct
23 Correct 190 ms 24064 KB Output is correct
24 Correct 171 ms 24064 KB Output is correct
25 Correct 71 ms 10100 KB Output is correct
26 Correct 72 ms 10104 KB Output is correct
27 Correct 176 ms 24116 KB Output is correct
28 Correct 166 ms 24044 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 0 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 1 ms 212 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 175 ms 22188 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1108 KB Output is correct
41 Correct 164 ms 22028 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 596 KB Output is correct
45 Correct 74 ms 8192 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 44 ms 5724 KB Output is correct
50 Correct 172 ms 22092 KB Output is correct
51 Correct 167 ms 22136 KB Output is correct
52 Correct 175 ms 22020 KB Output is correct
53 Correct 70 ms 12236 KB Output is correct
54 Correct 70 ms 8192 KB Output is correct
55 Correct 173 ms 22088 KB Output is correct
56 Correct 173 ms 22116 KB Output is correct
57 Correct 75 ms 12288 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 43 ms 5768 KB Output is correct
62 Correct 166 ms 22152 KB Output is correct
63 Correct 174 ms 22028 KB Output is correct
64 Correct 175 ms 22092 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 44 ms 5724 KB Output is correct
67 Correct 168 ms 22032 KB Output is correct
68 Correct 166 ms 22144 KB Output is correct
69 Correct 180 ms 22020 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 42 ms 5740 KB Output is correct
74 Correct 172 ms 22024 KB Output is correct
75 Correct 171 ms 22160 KB Output is correct
76 Correct 167 ms 22156 KB Output is correct
77 Correct 168 ms 22092 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 3 ms 596 KB Output is correct
81 Correct 77 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 296 KB Output is correct
85 Correct 44 ms 6256 KB Output is correct
86 Correct 70 ms 10096 KB Output is correct
87 Correct 73 ms 10096 KB Output is correct
88 Correct 71 ms 10060 KB Output is correct
89 Correct 73 ms 14196 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 4 ms 672 KB Output is correct
93 Correct 73 ms 10108 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 300 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 18 ms 2752 KB Output is correct
98 Correct 71 ms 10104 KB Output is correct
99 Correct 72 ms 10032 KB Output is correct
100 Correct 70 ms 10108 KB Output is correct
101 Correct 72 ms 10112 KB Output is correct
102 Correct 76 ms 10108 KB Output is correct
103 Correct 74 ms 10096 KB Output is correct
104 Correct 69 ms 10112 KB Output is correct
105 Correct 80 ms 10108 KB Output is correct