Submission #1015497

# Submission time Handle Problem Language Result Execution time Memory
1015497 2024-07-06T11:54:41 Z AliHasanli Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
172 ms 32724 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int sz[1001],par[1001],vis[1001];
int find(int a){
	if(a==par[a]) return a;
	int x=find(par[a]);
	par[a]=x;
	return x;
}
void join(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(sz[x]<sz[y]) swap(x,y);
	else if(sz[x]==sz[y] && x>y) swap(x,y);
	sz[x]+=sz[y];
	par[y]=x;
}
vector<pair<int,int>> node[4];
vector<int> v[1001],x,y;
int construct(vector<vector<int>> p) {
	int n = p.size();
	for(int i=0;i<n;i++){
		sz[i]=1;
		par[i]=i;
		for(int j=0;j<n;j++){
			node[p[i][j]].push_back({i,j});
		}
	}
	vector<vector<int>> answer(n,vector<int> (n,0));
	for(pair<int,int>P:node[1]) join(P.first,P.second);
	for(int i=0;i<n;i++){
		v[find(i)].push_back(i);
	}
	for(int i=0;i<n;i++){
		if(v[i].size()==0) continue;
		for(int j=1;j<v[i].size();j++){
			vis[v[i][j]]=1;
			answer[v[i][0]][v[i][j]]=answer[v[i][j]][v[i][0]]=1;
		}
		v[i].clear();
	}
	for(pair<int,int>P:node[2]) join(P.first,P.second);
	for(int i=0;i<n;i++){
		if(!vis[i]) v[find(i)].push_back(i);
	}
	for(int i=0;i<n;i++){
		if(v[i].size()<2) continue;
		if(v[i].size()==2) return 0;
		answer[v[i][0]][v[i].back()]=answer[v[i].back()][v[i][0]]=1;
		for(int j=1;j<v[i].size();j++){
			answer[v[i][j-1]][v[i][j]]=answer[v[i][j]][v[i][j-1]]=1;
		}
	}
	if(node[3].size()!=0) return 0;
	for(pair<int,int>P:node[0])
		if(find(P.first)==find(P.second)) return 0;
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for(int j=1;j<v[i].size();j++){
      |               ~^~~~~~~~~~~~
supertrees.cpp:53:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int j=1;j<v[i].size();j++){
      |               ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1620 KB Output is correct
7 Correct 125 ms 32132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1620 KB Output is correct
7 Correct 125 ms 32132 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1720 KB Output is correct
13 Correct 121 ms 31928 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1240 KB Output is correct
17 Correct 76 ms 22384 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 31 ms 8184 KB Output is correct
21 Correct 153 ms 31832 KB Output is correct
22 Correct 129 ms 31872 KB Output is correct
23 Correct 125 ms 31896 KB Output is correct
24 Correct 131 ms 31920 KB Output is correct
25 Correct 61 ms 21980 KB Output is correct
26 Correct 70 ms 22016 KB Output is correct
27 Correct 172 ms 31988 KB Output is correct
28 Correct 137 ms 31928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1748 KB Output is correct
9 Correct 170 ms 31920 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1592 KB Output is correct
13 Correct 120 ms 31868 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 69 ms 22108 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 34 ms 8192 KB Output is correct
22 Correct 148 ms 32724 KB Output is correct
23 Correct 126 ms 32264 KB Output is correct
24 Correct 171 ms 32020 KB Output is correct
25 Correct 68 ms 22140 KB Output is correct
26 Correct 59 ms 21936 KB Output is correct
27 Correct 119 ms 31876 KB Output is correct
28 Correct 148 ms 31980 KB Output is correct
29 Correct 57 ms 22016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 39 ms 8384 KB Output is correct
5 Correct 117 ms 32416 KB Output is correct
6 Correct 131 ms 31984 KB Output is correct
7 Correct 123 ms 31864 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 31 ms 8384 KB Output is correct
10 Correct 124 ms 32464 KB Output is correct
11 Correct 125 ms 31868 KB Output is correct
12 Correct 139 ms 31984 KB Output is correct
13 Correct 0 ms 464 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 30 ms 8384 KB Output is correct
17 Correct 115 ms 31952 KB Output is correct
18 Correct 163 ms 32400 KB Output is correct
19 Correct 116 ms 31932 KB Output is correct
20 Correct 118 ms 32004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1620 KB Output is correct
7 Correct 125 ms 32132 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1720 KB Output is correct
13 Correct 121 ms 31928 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1240 KB Output is correct
17 Correct 76 ms 22384 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 31 ms 8184 KB Output is correct
21 Correct 153 ms 31832 KB Output is correct
22 Correct 129 ms 31872 KB Output is correct
23 Correct 125 ms 31896 KB Output is correct
24 Correct 131 ms 31920 KB Output is correct
25 Correct 61 ms 21980 KB Output is correct
26 Correct 70 ms 22016 KB Output is correct
27 Correct 172 ms 31988 KB Output is correct
28 Correct 137 ms 31928 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1748 KB Output is correct
37 Correct 170 ms 31920 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 5 ms 1592 KB Output is correct
41 Correct 120 ms 31868 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 3 ms 1372 KB Output is correct
45 Correct 69 ms 22108 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 34 ms 8192 KB Output is correct
50 Correct 148 ms 32724 KB Output is correct
51 Correct 126 ms 32264 KB Output is correct
52 Correct 171 ms 32020 KB Output is correct
53 Correct 68 ms 22140 KB Output is correct
54 Correct 59 ms 21936 KB Output is correct
55 Correct 119 ms 31876 KB Output is correct
56 Correct 148 ms 31980 KB Output is correct
57 Correct 57 ms 22016 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 1372 KB Output is correct
61 Correct 70 ms 23408 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 412 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 37 ms 8272 KB Output is correct
66 Correct 60 ms 22064 KB Output is correct
67 Correct 71 ms 23260 KB Output is correct
68 Correct 59 ms 21960 KB Output is correct
69 Correct 59 ms 21956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1620 KB Output is correct
7 Correct 125 ms 32132 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1720 KB Output is correct
13 Correct 121 ms 31928 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1240 KB Output is correct
17 Correct 76 ms 22384 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 31 ms 8184 KB Output is correct
21 Correct 153 ms 31832 KB Output is correct
22 Correct 129 ms 31872 KB Output is correct
23 Correct 125 ms 31896 KB Output is correct
24 Correct 131 ms 31920 KB Output is correct
25 Correct 61 ms 21980 KB Output is correct
26 Correct 70 ms 22016 KB Output is correct
27 Correct 172 ms 31988 KB Output is correct
28 Correct 137 ms 31928 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1748 KB Output is correct
37 Correct 170 ms 31920 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 5 ms 1592 KB Output is correct
41 Correct 120 ms 31868 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 3 ms 1372 KB Output is correct
45 Correct 69 ms 22108 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 34 ms 8192 KB Output is correct
50 Correct 148 ms 32724 KB Output is correct
51 Correct 126 ms 32264 KB Output is correct
52 Correct 171 ms 32020 KB Output is correct
53 Correct 68 ms 22140 KB Output is correct
54 Correct 59 ms 21936 KB Output is correct
55 Correct 119 ms 31876 KB Output is correct
56 Correct 148 ms 31980 KB Output is correct
57 Correct 57 ms 22016 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 39 ms 8384 KB Output is correct
62 Correct 117 ms 32416 KB Output is correct
63 Correct 131 ms 31984 KB Output is correct
64 Correct 123 ms 31864 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 31 ms 8384 KB Output is correct
67 Correct 124 ms 32464 KB Output is correct
68 Correct 125 ms 31868 KB Output is correct
69 Correct 139 ms 31984 KB Output is correct
70 Correct 0 ms 464 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 464 KB Output is correct
73 Correct 30 ms 8384 KB Output is correct
74 Correct 115 ms 31952 KB Output is correct
75 Correct 163 ms 32400 KB Output is correct
76 Correct 116 ms 31932 KB Output is correct
77 Correct 118 ms 32004 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 3 ms 1372 KB Output is correct
81 Correct 70 ms 23408 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 412 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 37 ms 8272 KB Output is correct
86 Correct 60 ms 22064 KB Output is correct
87 Correct 71 ms 23260 KB Output is correct
88 Correct 59 ms 21960 KB Output is correct
89 Correct 59 ms 21956 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 344 KB Output is correct
92 Correct 3 ms 1372 KB Output is correct
93 Correct 68 ms 22084 KB Output is correct
94 Correct 0 ms 344 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 17 ms 5896 KB Output is correct
98 Correct 67 ms 22128 KB Output is correct
99 Correct 60 ms 22832 KB Output is correct
100 Correct 53 ms 21956 KB Output is correct
101 Correct 59 ms 22172 KB Output is correct
102 Correct 59 ms 21900 KB Output is correct
103 Correct 61 ms 22144 KB Output is correct
104 Correct 62 ms 21932 KB Output is correct
105 Correct 67 ms 21932 KB Output is correct