답안 #827068

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827068 2023-08-16T08:31:07 Z minhcool 슈퍼트리 잇기 (IOI20_supertrees) C++17
96 / 100
187 ms 38180 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] == 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:25: 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:126:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |       for(int j = 0; j < v2.size(); j++){
      |                      ~~^~~~~~~~~~~
supertrees.cpp:134:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  134 |       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 8 ms 14404 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 10 ms 14408 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 15 ms 15344 KB Output is correct
7 Correct 176 ms 38064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 8 ms 14404 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 10 ms 14408 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 15 ms 15344 KB Output is correct
7 Correct 176 ms 38064 KB Output is correct
8 Correct 9 ms 14376 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14316 KB Output is correct
12 Correct 14 ms 15312 KB Output is correct
13 Correct 177 ms 38172 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 14772 KB Output is correct
17 Correct 69 ms 24204 KB Output is correct
18 Correct 8 ms 14404 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 49 ms 20376 KB Output is correct
21 Correct 173 ms 38156 KB Output is correct
22 Correct 169 ms 38168 KB Output is correct
23 Correct 183 ms 38120 KB Output is correct
24 Correct 166 ms 38092 KB Output is correct
25 Correct 70 ms 24208 KB Output is correct
26 Correct 64 ms 24204 KB Output is correct
27 Correct 177 ms 38156 KB Output is correct
28 Correct 168 ms 38160 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 8 ms 14412 KB Output is correct
6 Correct 8 ms 14404 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 14 ms 15364 KB Output is correct
9 Correct 165 ms 38156 KB Output is correct
10 Correct 7 ms 14364 KB Output is correct
11 Correct 7 ms 14408 KB Output is correct
12 Correct 15 ms 15392 KB Output is correct
13 Correct 169 ms 38180 KB Output is correct
14 Correct 7 ms 14404 KB Output is correct
15 Correct 7 ms 14392 KB Output is correct
16 Correct 10 ms 14804 KB Output is correct
17 Correct 69 ms 24208 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
19 Correct 9 ms 14404 KB Output is correct
20 Correct 7 ms 14412 KB Output is correct
21 Correct 57 ms 20300 KB Output is correct
22 Correct 172 ms 38156 KB Output is correct
23 Correct 174 ms 38160 KB Output is correct
24 Correct 175 ms 38164 KB Output is correct
25 Correct 72 ms 28236 KB Output is correct
26 Correct 65 ms 24208 KB Output is correct
27 Correct 178 ms 38128 KB Output is correct
28 Correct 185 ms 38156 KB Output is correct
29 Correct 70 ms 28176 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 14408 KB Output is correct
4 Correct 49 ms 20384 KB Output is correct
5 Correct 171 ms 38048 KB Output is correct
6 Correct 169 ms 38172 KB Output is correct
7 Correct 180 ms 38160 KB Output is correct
8 Correct 7 ms 14404 KB Output is correct
9 Correct 49 ms 20300 KB Output is correct
10 Correct 187 ms 38108 KB Output is correct
11 Correct 170 ms 38092 KB Output is correct
12 Correct 177 ms 38148 KB Output is correct
13 Correct 7 ms 14400 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14420 KB Output is correct
16 Correct 48 ms 20376 KB Output is correct
17 Correct 171 ms 38012 KB Output is correct
18 Correct 183 ms 38068 KB Output is correct
19 Correct 187 ms 38160 KB Output is correct
20 Correct 166 ms 38036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 8 ms 14404 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 10 ms 14408 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 15 ms 15344 KB Output is correct
7 Correct 176 ms 38064 KB Output is correct
8 Correct 9 ms 14376 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14316 KB Output is correct
12 Correct 14 ms 15312 KB Output is correct
13 Correct 177 ms 38172 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 14772 KB Output is correct
17 Correct 69 ms 24204 KB Output is correct
18 Correct 8 ms 14404 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 49 ms 20376 KB Output is correct
21 Correct 173 ms 38156 KB Output is correct
22 Correct 169 ms 38168 KB Output is correct
23 Correct 183 ms 38120 KB Output is correct
24 Correct 166 ms 38092 KB Output is correct
25 Correct 70 ms 24208 KB Output is correct
26 Correct 64 ms 24204 KB Output is correct
27 Correct 177 ms 38156 KB Output is correct
28 Correct 168 ms 38160 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 8 ms 14412 KB Output is correct
34 Correct 8 ms 14404 KB Output is correct
35 Correct 7 ms 14420 KB Output is correct
36 Correct 14 ms 15364 KB Output is correct
37 Correct 165 ms 38156 KB Output is correct
38 Correct 7 ms 14364 KB Output is correct
39 Correct 7 ms 14408 KB Output is correct
40 Correct 15 ms 15392 KB Output is correct
41 Correct 169 ms 38180 KB Output is correct
42 Correct 7 ms 14404 KB Output is correct
43 Correct 7 ms 14392 KB Output is correct
44 Correct 10 ms 14804 KB Output is correct
45 Correct 69 ms 24208 KB Output is correct
46 Correct 9 ms 14420 KB Output is correct
47 Correct 9 ms 14404 KB Output is correct
48 Correct 7 ms 14412 KB Output is correct
49 Correct 57 ms 20300 KB Output is correct
50 Correct 172 ms 38156 KB Output is correct
51 Correct 174 ms 38160 KB Output is correct
52 Correct 175 ms 38164 KB Output is correct
53 Correct 72 ms 28236 KB Output is correct
54 Correct 65 ms 24208 KB Output is correct
55 Correct 178 ms 38128 KB Output is correct
56 Correct 185 ms 38156 KB Output is correct
57 Correct 70 ms 28176 KB Output is correct
58 Correct 7 ms 14420 KB Output is correct
59 Correct 7 ms 14420 KB Output is correct
60 Correct 10 ms 14804 KB Output is correct
61 Correct 71 ms 24204 KB Output is correct
62 Correct 7 ms 14412 KB Output is correct
63 Correct 7 ms 14340 KB Output is correct
64 Correct 7 ms 14400 KB Output is correct
65 Correct 48 ms 20288 KB Output is correct
66 Correct 66 ms 24204 KB Output is correct
67 Correct 72 ms 24208 KB Output is correct
68 Correct 68 ms 24208 KB Output is correct
69 Correct 70 ms 28184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 8 ms 14404 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 10 ms 14408 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 15 ms 15344 KB Output is correct
7 Correct 176 ms 38064 KB Output is correct
8 Correct 9 ms 14376 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14316 KB Output is correct
12 Correct 14 ms 15312 KB Output is correct
13 Correct 177 ms 38172 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 14772 KB Output is correct
17 Correct 69 ms 24204 KB Output is correct
18 Correct 8 ms 14404 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 49 ms 20376 KB Output is correct
21 Correct 173 ms 38156 KB Output is correct
22 Correct 169 ms 38168 KB Output is correct
23 Correct 183 ms 38120 KB Output is correct
24 Correct 166 ms 38092 KB Output is correct
25 Correct 70 ms 24208 KB Output is correct
26 Correct 64 ms 24204 KB Output is correct
27 Correct 177 ms 38156 KB Output is correct
28 Correct 168 ms 38160 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 8 ms 14412 KB Output is correct
34 Correct 8 ms 14404 KB Output is correct
35 Correct 7 ms 14420 KB Output is correct
36 Correct 14 ms 15364 KB Output is correct
37 Correct 165 ms 38156 KB Output is correct
38 Correct 7 ms 14364 KB Output is correct
39 Correct 7 ms 14408 KB Output is correct
40 Correct 15 ms 15392 KB Output is correct
41 Correct 169 ms 38180 KB Output is correct
42 Correct 7 ms 14404 KB Output is correct
43 Correct 7 ms 14392 KB Output is correct
44 Correct 10 ms 14804 KB Output is correct
45 Correct 69 ms 24208 KB Output is correct
46 Correct 9 ms 14420 KB Output is correct
47 Correct 9 ms 14404 KB Output is correct
48 Correct 7 ms 14412 KB Output is correct
49 Correct 57 ms 20300 KB Output is correct
50 Correct 172 ms 38156 KB Output is correct
51 Correct 174 ms 38160 KB Output is correct
52 Correct 175 ms 38164 KB Output is correct
53 Correct 72 ms 28236 KB Output is correct
54 Correct 65 ms 24208 KB Output is correct
55 Correct 178 ms 38128 KB Output is correct
56 Correct 185 ms 38156 KB Output is correct
57 Correct 70 ms 28176 KB Output is correct
58 Correct 7 ms 14420 KB Output is correct
59 Correct 7 ms 14420 KB Output is correct
60 Correct 7 ms 14408 KB Output is correct
61 Correct 49 ms 20384 KB Output is correct
62 Correct 171 ms 38048 KB Output is correct
63 Correct 169 ms 38172 KB Output is correct
64 Correct 180 ms 38160 KB Output is correct
65 Correct 7 ms 14404 KB Output is correct
66 Correct 49 ms 20300 KB Output is correct
67 Correct 187 ms 38108 KB Output is correct
68 Correct 170 ms 38092 KB Output is correct
69 Correct 177 ms 38148 KB Output is correct
70 Correct 7 ms 14400 KB Output is correct
71 Correct 8 ms 14420 KB Output is correct
72 Correct 8 ms 14420 KB Output is correct
73 Correct 48 ms 20376 KB Output is correct
74 Correct 171 ms 38012 KB Output is correct
75 Correct 183 ms 38068 KB Output is correct
76 Correct 187 ms 38160 KB Output is correct
77 Correct 166 ms 38036 KB Output is correct
78 Correct 7 ms 14420 KB Output is correct
79 Correct 7 ms 14420 KB Output is correct
80 Correct 10 ms 14804 KB Output is correct
81 Correct 71 ms 24204 KB Output is correct
82 Correct 7 ms 14412 KB Output is correct
83 Correct 7 ms 14340 KB Output is correct
84 Correct 7 ms 14400 KB Output is correct
85 Correct 48 ms 20288 KB Output is correct
86 Correct 66 ms 24204 KB Output is correct
87 Correct 72 ms 24208 KB Output is correct
88 Correct 68 ms 24208 KB Output is correct
89 Correct 70 ms 28184 KB Output is correct
90 Correct 7 ms 14420 KB Output is correct
91 Correct 6 ms 14420 KB Output is correct
92 Correct 9 ms 14776 KB Output is correct
93 Correct 68 ms 24224 KB Output is correct
94 Incorrect 7 ms 14420 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -