답안 #827072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827072 2023-08-16T08:33:42 Z minhcool 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
195 ms 36596 KB
        //#define local
        #ifndef local
        #include "supertrees.h"
        #endif
        #include<bits/stdc++.h>
        #include <ext/pb_ds/assoc_container.hpp>
        using namespace __gnu_pbds;
        using namespace std;
         
        //#define int long long
        #define fi first
        #define se second
        #define pb push_back
        #define mp make_pair
         
        typedef pair<int, int> ii;
        typedef pair<ii, int> iii;
        typedef pair<ii, ii> iiii;
         
        const int N = 3e5 + 5;
         
        const int oo = 1e18 + 7, mod = 1e9 + 7;
         
        mt19937 rng(1);
         
        int rnd(int l, int r){
        	int temp = rng() % (r - l + 1);
        	return abs(temp) + l;
        }
         
        int sz1[N], rt1[N];
         
        int sz2[N], rt2[N];
         
        int root1(int x){
        	return (x == rt1[x] ? x : rt1[x] = root1(rt1[x]));
        }
         
        void merge1(int x, int y){
        	x = root1(x), y = root1(y);
        	if(x == y) return;
        	if(sz1[x] < sz1[y]) swap(x, y);
        	sz1[x] += sz1[y];
        	rt1[y] = x;
        }
         
        int root2(int x){
        	return (x == rt2[x] ? x : rt2[x] = root2(rt2[x]));
        }
         
        void merge2(int x, int y){
        	x = root2(x), y = root2(y);
        	if(x == y) return;
        	if(sz2[x] < sz2[y]) swap(x, y);
        	sz2[x] += sz2[y];
        	rt2[y] = x;
        }
         
        vector<int> vc1[N], vc2[N];
         
        bool ok[N];
         
        int construct(vector<vector<int>> p) {
        	int n = p.size();
        	for(int i = 0; i < n; i++){
        		vc1[i].clear(), vc2[i].clear();
        	}
        	//int n = p.size();
        	for(int i = 0; i < n; i++){
        		rt1[i] = i, sz1[i] = 1;
        		rt2[i] = i, sz2[i] = 1;
        	}
        	for(int i = 0; i < n; i++){
        		for(int j = 0; j < n; j++){
        			if(i == j) continue;
                    if(p[i][j] == 3) return 0;
        			if(p[i][j] == 0){
        				if(root1(i) == root1(j)) return 0;
        			//	if(root2(i) == root2(j)) return 0;
        			}
        			if(p[i][j] >= 1){
        			//	if(root2(i) == root2(j)) return 0;
        				merge1(i, j);
        			}
        		}
        	}
        	for(int i = 0; i < n; i++){
        		for(int j = 0; j < n; j++){
        			if(i == j) continue;
        			if(p[i][j] == 0){
        				if(root1(i) == root1(j)) return 0;
        			//	if(root2(i) == root2(j)) return 0;
        			}
        		}
        	}
        	for(int i = 0; i < n; i++) vc1[root1(i)].pb(i);
        	vector<vector<int>> answer;
        	answer.resize(n);
        	for(int i = 0; i < n; i++) answer[i].resize(n);
        	for(int i = 0; i < n; i++){
        		if(root1(i) != i) continue;
        		vector<int> v;
        		//for(auto it : vc1[i]) ok[it] = 0;
        		//for(auto it : v) ok[it] = 1;
        		//if(v.size() <= 1 && has2) return 0;
        		//if(!has2) continue;
        		for(auto it : vc1[i]){
        			for(auto it2 : vc1[i]){
        				if(ok[it] || ok[it2] || it == it2) continue;
        				if(p[it][it2] == 1) merge2(it, it2);
        			}
        		}
        		for(auto it : vc1[i]) if(!ok[it]) vc2[root2(it)].pb(it);
        		vector<int> v2;
        		for(auto it : vc1[i]){
        			if(ok[it] || root2(it) != it) continue;
        			v2.pb(it);
        			for(auto it2 : vc2[it]){
        				for(auto it3 : vc2[it]){
        					if(it2 == it3) continue;
        					if(p[it2][it3] == 2) return 0;
        				}
        			}
        		}
        		if(v2.size() == 2) return 0;
        		//if(v2.size() > v.size()) return 0;
        		for(int j = 0; j < v2.size(); j++){
        			//cout << v2[j] << "\n";
        			//answer[v[j]][v2[j]] = 1;
        			for(auto it : vc2[v2[j]]){
        				if(it == v2[j]) continue;
        				answer[it][v2[j]] = answer[v2[j]][it] = 1;
        			}
        		}
        		if(v2.size() > 2) for(int j = 0; j < v2.size(); j++) answer[v2[j]][v2[(j + 1) % v2.size()]] = answer[v2[(j + 1) % v2.size()]][v2[j]] = 1;
        	}
        	build(answer);
        	return 1;
        }
         
        #ifdef local
        void process(){
        	int a, b;
        	cin >> a >> b;
        	cout << a + b << "\n";
        }
         
        signed main(){
        	ios_base::sync_with_stdio(0);
        	cin.tie(0);
        	int t;
        	cin >> t;
        	while(t--) process();
        }
        #endif

Compilation message

supertrees.cpp:22:29: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   22 |         const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                        ~~~~~^~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:127:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |           for(int j = 0; j < v2.size(); j++){
      |                          ~~^~~~~~~~~~~
supertrees.cpp:135:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |           if(v2.size() > 2) for(int j = 0; j < v2.size(); j++) answer[v2[j]][v2[(j + 1) % v2.size()]] = answer[v2[(j + 1) % v2.size()]][v2[j]] = 1;
      |                                            ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 14 ms 15312 KB Output is correct
7 Correct 165 ms 36508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 14 ms 15312 KB Output is correct
7 Correct 165 ms 36508 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14396 KB Output is correct
12 Correct 13 ms 15316 KB Output is correct
13 Correct 160 ms 36568 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14408 KB Output is correct
16 Correct 10 ms 14796 KB Output is correct
17 Correct 68 ms 22588 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 7 ms 14420 KB Output is correct
20 Correct 47 ms 20172 KB Output is correct
21 Correct 164 ms 36512 KB Output is correct
22 Correct 172 ms 36516 KB Output is correct
23 Correct 191 ms 36544 KB Output is correct
24 Correct 160 ms 36520 KB Output is correct
25 Correct 67 ms 22692 KB Output is correct
26 Correct 64 ms 22600 KB Output is correct
27 Correct 168 ms 36596 KB Output is correct
28 Correct 167 ms 36584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 8 ms 14316 KB Output is correct
7 Correct 8 ms 14424 KB Output is correct
8 Correct 13 ms 15340 KB Output is correct
9 Correct 157 ms 36520 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 13 ms 15316 KB Output is correct
13 Correct 171 ms 36568 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 9 ms 14768 KB Output is correct
17 Correct 73 ms 22732 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 7 ms 14420 KB Output is correct
20 Correct 7 ms 14404 KB Output is correct
21 Correct 46 ms 20020 KB Output is correct
22 Correct 165 ms 36264 KB Output is correct
23 Correct 164 ms 36292 KB Output is correct
24 Correct 168 ms 36172 KB Output is correct
25 Correct 68 ms 26272 KB Output is correct
26 Correct 65 ms 22304 KB Output is correct
27 Correct 168 ms 36140 KB Output is correct
28 Correct 169 ms 36140 KB Output is correct
29 Correct 69 ms 26280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14424 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 46 ms 19808 KB Output is correct
5 Correct 164 ms 36144 KB Output is correct
6 Correct 164 ms 36136 KB Output is correct
7 Correct 169 ms 36172 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 47 ms 19820 KB Output is correct
10 Correct 180 ms 36164 KB Output is correct
11 Correct 162 ms 36124 KB Output is correct
12 Correct 167 ms 36104 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 6 ms 14420 KB Output is correct
16 Correct 46 ms 19824 KB Output is correct
17 Correct 164 ms 36212 KB Output is correct
18 Correct 167 ms 36124 KB Output is correct
19 Correct 195 ms 36140 KB Output is correct
20 Correct 160 ms 36428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 14 ms 15312 KB Output is correct
7 Correct 165 ms 36508 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14396 KB Output is correct
12 Correct 13 ms 15316 KB Output is correct
13 Correct 160 ms 36568 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14408 KB Output is correct
16 Correct 10 ms 14796 KB Output is correct
17 Correct 68 ms 22588 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 7 ms 14420 KB Output is correct
20 Correct 47 ms 20172 KB Output is correct
21 Correct 164 ms 36512 KB Output is correct
22 Correct 172 ms 36516 KB Output is correct
23 Correct 191 ms 36544 KB Output is correct
24 Correct 160 ms 36520 KB Output is correct
25 Correct 67 ms 22692 KB Output is correct
26 Correct 64 ms 22600 KB Output is correct
27 Correct 168 ms 36596 KB Output is correct
28 Correct 167 ms 36584 KB Output is correct
29 Correct 7 ms 14420 KB Output is correct
30 Correct 7 ms 14420 KB Output is correct
31 Correct 7 ms 14420 KB Output is correct
32 Correct 7 ms 14420 KB Output is correct
33 Correct 7 ms 14420 KB Output is correct
34 Correct 8 ms 14316 KB Output is correct
35 Correct 8 ms 14424 KB Output is correct
36 Correct 13 ms 15340 KB Output is correct
37 Correct 157 ms 36520 KB Output is correct
38 Correct 7 ms 14420 KB Output is correct
39 Correct 7 ms 14420 KB Output is correct
40 Correct 13 ms 15316 KB Output is correct
41 Correct 171 ms 36568 KB Output is correct
42 Correct 7 ms 14420 KB Output is correct
43 Correct 7 ms 14420 KB Output is correct
44 Correct 9 ms 14768 KB Output is correct
45 Correct 73 ms 22732 KB Output is correct
46 Correct 7 ms 14420 KB Output is correct
47 Correct 7 ms 14420 KB Output is correct
48 Correct 7 ms 14404 KB Output is correct
49 Correct 46 ms 20020 KB Output is correct
50 Correct 165 ms 36264 KB Output is correct
51 Correct 164 ms 36292 KB Output is correct
52 Correct 168 ms 36172 KB Output is correct
53 Correct 68 ms 26272 KB Output is correct
54 Correct 65 ms 22304 KB Output is correct
55 Correct 168 ms 36140 KB Output is correct
56 Correct 169 ms 36140 KB Output is correct
57 Correct 69 ms 26280 KB Output is correct
58 Correct 7 ms 14420 KB Output is correct
59 Correct 7 ms 14324 KB Output is correct
60 Correct 9 ms 14688 KB Output is correct
61 Correct 66 ms 22316 KB Output is correct
62 Correct 7 ms 14304 KB Output is correct
63 Correct 7 ms 14420 KB Output is correct
64 Correct 7 ms 14420 KB Output is correct
65 Correct 47 ms 19860 KB Output is correct
66 Correct 65 ms 22220 KB Output is correct
67 Correct 66 ms 22304 KB Output is correct
68 Correct 64 ms 22316 KB Output is correct
69 Correct 69 ms 26268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 14 ms 15312 KB Output is correct
7 Correct 165 ms 36508 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14396 KB Output is correct
12 Correct 13 ms 15316 KB Output is correct
13 Correct 160 ms 36568 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14408 KB Output is correct
16 Correct 10 ms 14796 KB Output is correct
17 Correct 68 ms 22588 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 7 ms 14420 KB Output is correct
20 Correct 47 ms 20172 KB Output is correct
21 Correct 164 ms 36512 KB Output is correct
22 Correct 172 ms 36516 KB Output is correct
23 Correct 191 ms 36544 KB Output is correct
24 Correct 160 ms 36520 KB Output is correct
25 Correct 67 ms 22692 KB Output is correct
26 Correct 64 ms 22600 KB Output is correct
27 Correct 168 ms 36596 KB Output is correct
28 Correct 167 ms 36584 KB Output is correct
29 Correct 7 ms 14420 KB Output is correct
30 Correct 7 ms 14420 KB Output is correct
31 Correct 7 ms 14420 KB Output is correct
32 Correct 7 ms 14420 KB Output is correct
33 Correct 7 ms 14420 KB Output is correct
34 Correct 8 ms 14316 KB Output is correct
35 Correct 8 ms 14424 KB Output is correct
36 Correct 13 ms 15340 KB Output is correct
37 Correct 157 ms 36520 KB Output is correct
38 Correct 7 ms 14420 KB Output is correct
39 Correct 7 ms 14420 KB Output is correct
40 Correct 13 ms 15316 KB Output is correct
41 Correct 171 ms 36568 KB Output is correct
42 Correct 7 ms 14420 KB Output is correct
43 Correct 7 ms 14420 KB Output is correct
44 Correct 9 ms 14768 KB Output is correct
45 Correct 73 ms 22732 KB Output is correct
46 Correct 7 ms 14420 KB Output is correct
47 Correct 7 ms 14420 KB Output is correct
48 Correct 7 ms 14404 KB Output is correct
49 Correct 46 ms 20020 KB Output is correct
50 Correct 165 ms 36264 KB Output is correct
51 Correct 164 ms 36292 KB Output is correct
52 Correct 168 ms 36172 KB Output is correct
53 Correct 68 ms 26272 KB Output is correct
54 Correct 65 ms 22304 KB Output is correct
55 Correct 168 ms 36140 KB Output is correct
56 Correct 169 ms 36140 KB Output is correct
57 Correct 69 ms 26280 KB Output is correct
58 Correct 7 ms 14420 KB Output is correct
59 Correct 7 ms 14424 KB Output is correct
60 Correct 7 ms 14420 KB Output is correct
61 Correct 46 ms 19808 KB Output is correct
62 Correct 164 ms 36144 KB Output is correct
63 Correct 164 ms 36136 KB Output is correct
64 Correct 169 ms 36172 KB Output is correct
65 Correct 7 ms 14420 KB Output is correct
66 Correct 47 ms 19820 KB Output is correct
67 Correct 180 ms 36164 KB Output is correct
68 Correct 162 ms 36124 KB Output is correct
69 Correct 167 ms 36104 KB Output is correct
70 Correct 7 ms 14420 KB Output is correct
71 Correct 7 ms 14420 KB Output is correct
72 Correct 6 ms 14420 KB Output is correct
73 Correct 46 ms 19824 KB Output is correct
74 Correct 164 ms 36212 KB Output is correct
75 Correct 167 ms 36124 KB Output is correct
76 Correct 195 ms 36140 KB Output is correct
77 Correct 160 ms 36428 KB Output is correct
78 Correct 7 ms 14420 KB Output is correct
79 Correct 7 ms 14324 KB Output is correct
80 Correct 9 ms 14688 KB Output is correct
81 Correct 66 ms 22316 KB Output is correct
82 Correct 7 ms 14304 KB Output is correct
83 Correct 7 ms 14420 KB Output is correct
84 Correct 7 ms 14420 KB Output is correct
85 Correct 47 ms 19860 KB Output is correct
86 Correct 65 ms 22220 KB Output is correct
87 Correct 66 ms 22304 KB Output is correct
88 Correct 64 ms 22316 KB Output is correct
89 Correct 69 ms 26268 KB Output is correct
90 Correct 7 ms 14420 KB Output is correct
91 Correct 6 ms 14420 KB Output is correct
92 Correct 8 ms 14676 KB Output is correct
93 Correct 65 ms 22296 KB Output is correct
94 Correct 7 ms 14420 KB Output is correct
95 Correct 7 ms 14320 KB Output is correct
96 Correct 6 ms 14420 KB Output is correct
97 Correct 25 ms 16776 KB Output is correct
98 Correct 65 ms 24216 KB Output is correct
99 Correct 66 ms 24204 KB Output is correct
100 Correct 64 ms 24216 KB Output is correct
101 Correct 65 ms 24208 KB Output is correct
102 Correct 66 ms 24204 KB Output is correct
103 Correct 64 ms 24216 KB Output is correct
104 Correct 64 ms 24268 KB Output is correct
105 Correct 68 ms 24260 KB Output is correct