Submission #619816

# Submission time Handle Problem Language Result Execution time Memory
619816 2022-08-02T16:10:14 Z KLPP Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
285 ms 47244 KB
#include "supertrees.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long int lld;
#define trav(a,v) for(auto a:v)

class DSU{
	int sz[1000000];
	int parent[1000000];
	int n;
	public:
	void init(int N){
		n=N;
		rep(i,0,n)sz[i]=1,parent[i]=i;
	}
	int root(int x){
		if(x==parent[x])return x;
		parent[x]=root(parent[x]);
		return parent[x];
	}
	void merge(int a, int b){
		a=root(a);
		b=root(b);
		if(a==b)return;
		if(sz[a]<sz[b])swap(a,b);
		sz[a]+=sz[b];
		parent[b]=a;
	}
};
DSU D;
DSU D2;
vector<int> comp[1000000];
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	
	D.init(n);
	rep(i,0,n){
		rep(j,0,n){
			if(p[i][j]==3)return 0;
			if(p[i][j]==1)D.merge(i,j);
		}
	}
	rep(i,0,n)comp[D.root(i)].push_back(i);
	rep(i,0,n){
		bool B=true;
		rep(j,i+1,n){
			if(D.root(j)==D.root(i)){
				B=false;
				if(p[i][j]!=1){
					return 0;
				}
			}
		}
		if(B){
			rep(j,0,i){
				if(D.root(j)==D.root(i))answer[i][j]=1,answer[j][i]=1;
			}
		}
	}
	D2.init(n);
	rep(i,0,n){
		rep(j,0,n){
			if(p[i][j]==2){
				D2.merge(D.root(i),D.root(j));
			}
		}
	}
	vector<pair<int,int> >V;
	rep(i,0,n){
		if(D.root(i)==i){
			V.push_back({D2.root(i),i});
		}
	}
	sort(V.begin(),V.end());
	int bg=V[0].second;
	rep(i,0,V.size()){
		if(i<V.size()-1 && V[i].first==V[i+1].first){
			answer[V[i].second][V[i+1].second]=1;
			answer[V[i+1].second][V[i].second]=1;
		}else{
			if(answer[V[i].second][bg]==1){
				return 0;
			}else{
				answer[V[i].second][bg]=1;
				answer[bg][V[i].second]=1;
			}
			if(i<V.size())bg=V[i+1].second;
		}
	}
	rep(i,0,n){
		rep(j,0,n){
			if(p[i][j]==0 && D2.root(D.root(i))==D2.root(D.root(j))){
				//cout<<D2.root(D.root(i))<<" "<<D2.root(D.root(j))<<endl;
				return 0;
			}
		}
	}
	rep(i,0,n)answer[i][i]=0;
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:5:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(i,a,b) for(int i=a;i<b;i++)
......
   84 |  rep(i,0,V.size()){
      |      ~~~~~~~~~~~~                
supertrees.cpp:84:2: note: in expansion of macro 'rep'
   84 |  rep(i,0,V.size()){
      |  ^~~
supertrees.cpp:85:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   if(i<V.size()-1 && V[i].first==V[i+1].first){
      |      ~^~~~~~~~~~~
supertrees.cpp:95:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |    if(i<V.size())bg=V[i+1].second;
      |       ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 23748 KB Output is correct
3 Correct 13 ms 23720 KB Output is correct
4 Correct 14 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 23 ms 24784 KB Output is correct
7 Correct 207 ms 47040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 23748 KB Output is correct
3 Correct 13 ms 23720 KB Output is correct
4 Correct 14 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 23 ms 24784 KB Output is correct
7 Correct 207 ms 47040 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 13 ms 23764 KB Output is correct
12 Correct 21 ms 24780 KB Output is correct
13 Correct 184 ms 47140 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 14 ms 23764 KB Output is correct
16 Correct 17 ms 24288 KB Output is correct
17 Correct 98 ms 37148 KB Output is correct
18 Correct 13 ms 23768 KB Output is correct
19 Correct 13 ms 23792 KB Output is correct
20 Correct 58 ms 29776 KB Output is correct
21 Correct 183 ms 47032 KB Output is correct
22 Correct 193 ms 47244 KB Output is correct
23 Correct 207 ms 47064 KB Output is correct
24 Correct 193 ms 47072 KB Output is correct
25 Correct 88 ms 37200 KB Output is correct
26 Correct 94 ms 37260 KB Output is correct
27 Correct 194 ms 47080 KB Output is correct
28 Correct 203 ms 47176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 12 ms 23772 KB Output is correct
5 Correct 12 ms 23720 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 14 ms 23772 KB Output is correct
8 Correct 29 ms 24780 KB Output is correct
9 Correct 202 ms 46284 KB Output is correct
10 Correct 13 ms 23796 KB Output is correct
11 Correct 13 ms 23796 KB Output is correct
12 Correct 20 ms 24804 KB Output is correct
13 Correct 188 ms 46356 KB Output is correct
14 Correct 16 ms 23808 KB Output is correct
15 Correct 12 ms 23712 KB Output is correct
16 Correct 16 ms 24404 KB Output is correct
17 Correct 102 ms 36468 KB Output is correct
18 Correct 14 ms 23800 KB Output is correct
19 Correct 11 ms 23764 KB Output is correct
20 Correct 11 ms 23808 KB Output is correct
21 Correct 57 ms 29784 KB Output is correct
22 Correct 194 ms 46376 KB Output is correct
23 Correct 198 ms 46400 KB Output is correct
24 Correct 208 ms 46272 KB Output is correct
25 Correct 92 ms 36484 KB Output is correct
26 Correct 91 ms 36476 KB Output is correct
27 Correct 209 ms 46316 KB Output is correct
28 Correct 209 ms 46308 KB Output is correct
29 Correct 96 ms 36436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23788 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23732 KB Output is correct
4 Correct 70 ms 29736 KB Output is correct
5 Correct 226 ms 46308 KB Output is correct
6 Correct 195 ms 46284 KB Output is correct
7 Correct 285 ms 46260 KB Output is correct
8 Correct 16 ms 23764 KB Output is correct
9 Correct 57 ms 29788 KB Output is correct
10 Correct 220 ms 46328 KB Output is correct
11 Correct 187 ms 46316 KB Output is correct
12 Correct 197 ms 46324 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 14 ms 23704 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 66 ms 29688 KB Output is correct
17 Correct 193 ms 46316 KB Output is correct
18 Correct 198 ms 46280 KB Output is correct
19 Correct 206 ms 46284 KB Output is correct
20 Correct 192 ms 46300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 23748 KB Output is correct
3 Correct 13 ms 23720 KB Output is correct
4 Correct 14 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 23 ms 24784 KB Output is correct
7 Correct 207 ms 47040 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 13 ms 23764 KB Output is correct
12 Correct 21 ms 24780 KB Output is correct
13 Correct 184 ms 47140 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 14 ms 23764 KB Output is correct
16 Correct 17 ms 24288 KB Output is correct
17 Correct 98 ms 37148 KB Output is correct
18 Correct 13 ms 23768 KB Output is correct
19 Correct 13 ms 23792 KB Output is correct
20 Correct 58 ms 29776 KB Output is correct
21 Correct 183 ms 47032 KB Output is correct
22 Correct 193 ms 47244 KB Output is correct
23 Correct 207 ms 47064 KB Output is correct
24 Correct 193 ms 47072 KB Output is correct
25 Correct 88 ms 37200 KB Output is correct
26 Correct 94 ms 37260 KB Output is correct
27 Correct 194 ms 47080 KB Output is correct
28 Correct 203 ms 47176 KB Output is correct
29 Correct 13 ms 23764 KB Output is correct
30 Correct 13 ms 23764 KB Output is correct
31 Correct 13 ms 23764 KB Output is correct
32 Correct 12 ms 23772 KB Output is correct
33 Correct 12 ms 23720 KB Output is correct
34 Correct 12 ms 23764 KB Output is correct
35 Correct 14 ms 23772 KB Output is correct
36 Correct 29 ms 24780 KB Output is correct
37 Correct 202 ms 46284 KB Output is correct
38 Correct 13 ms 23796 KB Output is correct
39 Correct 13 ms 23796 KB Output is correct
40 Correct 20 ms 24804 KB Output is correct
41 Correct 188 ms 46356 KB Output is correct
42 Correct 16 ms 23808 KB Output is correct
43 Correct 12 ms 23712 KB Output is correct
44 Correct 16 ms 24404 KB Output is correct
45 Correct 102 ms 36468 KB Output is correct
46 Correct 14 ms 23800 KB Output is correct
47 Correct 11 ms 23764 KB Output is correct
48 Correct 11 ms 23808 KB Output is correct
49 Correct 57 ms 29784 KB Output is correct
50 Correct 194 ms 46376 KB Output is correct
51 Correct 198 ms 46400 KB Output is correct
52 Correct 208 ms 46272 KB Output is correct
53 Correct 92 ms 36484 KB Output is correct
54 Correct 91 ms 36476 KB Output is correct
55 Correct 209 ms 46316 KB Output is correct
56 Correct 209 ms 46308 KB Output is correct
57 Correct 96 ms 36436 KB Output is correct
58 Correct 12 ms 23796 KB Output is correct
59 Correct 15 ms 23712 KB Output is correct
60 Correct 15 ms 24316 KB Output is correct
61 Correct 99 ms 36336 KB Output is correct
62 Correct 14 ms 23764 KB Output is correct
63 Correct 13 ms 23792 KB Output is correct
64 Correct 13 ms 23792 KB Output is correct
65 Correct 56 ms 29812 KB Output is correct
66 Correct 105 ms 36380 KB Output is correct
67 Correct 97 ms 36416 KB Output is correct
68 Correct 102 ms 36376 KB Output is correct
69 Correct 93 ms 36432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 14 ms 23748 KB Output is correct
3 Correct 13 ms 23720 KB Output is correct
4 Correct 14 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 23 ms 24784 KB Output is correct
7 Correct 207 ms 47040 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 13 ms 23764 KB Output is correct
12 Correct 21 ms 24780 KB Output is correct
13 Correct 184 ms 47140 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 14 ms 23764 KB Output is correct
16 Correct 17 ms 24288 KB Output is correct
17 Correct 98 ms 37148 KB Output is correct
18 Correct 13 ms 23768 KB Output is correct
19 Correct 13 ms 23792 KB Output is correct
20 Correct 58 ms 29776 KB Output is correct
21 Correct 183 ms 47032 KB Output is correct
22 Correct 193 ms 47244 KB Output is correct
23 Correct 207 ms 47064 KB Output is correct
24 Correct 193 ms 47072 KB Output is correct
25 Correct 88 ms 37200 KB Output is correct
26 Correct 94 ms 37260 KB Output is correct
27 Correct 194 ms 47080 KB Output is correct
28 Correct 203 ms 47176 KB Output is correct
29 Correct 13 ms 23764 KB Output is correct
30 Correct 13 ms 23764 KB Output is correct
31 Correct 13 ms 23764 KB Output is correct
32 Correct 12 ms 23772 KB Output is correct
33 Correct 12 ms 23720 KB Output is correct
34 Correct 12 ms 23764 KB Output is correct
35 Correct 14 ms 23772 KB Output is correct
36 Correct 29 ms 24780 KB Output is correct
37 Correct 202 ms 46284 KB Output is correct
38 Correct 13 ms 23796 KB Output is correct
39 Correct 13 ms 23796 KB Output is correct
40 Correct 20 ms 24804 KB Output is correct
41 Correct 188 ms 46356 KB Output is correct
42 Correct 16 ms 23808 KB Output is correct
43 Correct 12 ms 23712 KB Output is correct
44 Correct 16 ms 24404 KB Output is correct
45 Correct 102 ms 36468 KB Output is correct
46 Correct 14 ms 23800 KB Output is correct
47 Correct 11 ms 23764 KB Output is correct
48 Correct 11 ms 23808 KB Output is correct
49 Correct 57 ms 29784 KB Output is correct
50 Correct 194 ms 46376 KB Output is correct
51 Correct 198 ms 46400 KB Output is correct
52 Correct 208 ms 46272 KB Output is correct
53 Correct 92 ms 36484 KB Output is correct
54 Correct 91 ms 36476 KB Output is correct
55 Correct 209 ms 46316 KB Output is correct
56 Correct 209 ms 46308 KB Output is correct
57 Correct 96 ms 36436 KB Output is correct
58 Correct 13 ms 23788 KB Output is correct
59 Correct 14 ms 23808 KB Output is correct
60 Correct 14 ms 23732 KB Output is correct
61 Correct 70 ms 29736 KB Output is correct
62 Correct 226 ms 46308 KB Output is correct
63 Correct 195 ms 46284 KB Output is correct
64 Correct 285 ms 46260 KB Output is correct
65 Correct 16 ms 23764 KB Output is correct
66 Correct 57 ms 29788 KB Output is correct
67 Correct 220 ms 46328 KB Output is correct
68 Correct 187 ms 46316 KB Output is correct
69 Correct 197 ms 46324 KB Output is correct
70 Correct 13 ms 23764 KB Output is correct
71 Correct 14 ms 23704 KB Output is correct
72 Correct 13 ms 23764 KB Output is correct
73 Correct 66 ms 29688 KB Output is correct
74 Correct 193 ms 46316 KB Output is correct
75 Correct 198 ms 46280 KB Output is correct
76 Correct 206 ms 46284 KB Output is correct
77 Correct 192 ms 46300 KB Output is correct
78 Correct 12 ms 23796 KB Output is correct
79 Correct 15 ms 23712 KB Output is correct
80 Correct 15 ms 24316 KB Output is correct
81 Correct 99 ms 36336 KB Output is correct
82 Correct 14 ms 23764 KB Output is correct
83 Correct 13 ms 23792 KB Output is correct
84 Correct 13 ms 23792 KB Output is correct
85 Correct 56 ms 29812 KB Output is correct
86 Correct 105 ms 36380 KB Output is correct
87 Correct 97 ms 36416 KB Output is correct
88 Correct 102 ms 36376 KB Output is correct
89 Correct 93 ms 36432 KB Output is correct
90 Correct 13 ms 23784 KB Output is correct
91 Correct 13 ms 23764 KB Output is correct
92 Correct 15 ms 24280 KB Output is correct
93 Correct 89 ms 36436 KB Output is correct
94 Correct 13 ms 23764 KB Output is correct
95 Correct 15 ms 23792 KB Output is correct
96 Correct 17 ms 23804 KB Output is correct
97 Correct 34 ms 27212 KB Output is correct
98 Correct 83 ms 37572 KB Output is correct
99 Correct 96 ms 37560 KB Output is correct
100 Correct 134 ms 37568 KB Output is correct
101 Correct 96 ms 37496 KB Output is correct
102 Correct 83 ms 37612 KB Output is correct
103 Correct 111 ms 37556 KB Output is correct
104 Correct 82 ms 37568 KB Output is correct
105 Correct 102 ms 37560 KB Output is correct