Submission #302704

# Submission time Handle Problem Language Result Execution time Memory
302704 2020-09-19T04:27:30 Z arnold518 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
282 ms 30200 KB
#include "supertrees.h"
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int MAXN = 1000;
 
int N, A[MAXN+10][MAXN+10], ans[MAXN+10][MAXN+10];
 
int par[MAXN+10];
vector<int> V[MAXN+10];
 
int Find(int x)
{
	if(x==par[x]) return x;
	return par[x]=Find(par[x]);
}
 
void Union(int x, int y)
{
	x=Find(x); y=Find(y);
	par[x]=y;
}
 
void addEdge(int x, int y)
{
	if(x==y) return;
	ans[x][y]=ans[y][x]=1;
}
 
int construct(vector<vector<int>> _P)
{
	N=_P.size();
	for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) A[i][j]=_P[i-1][j-1];
	for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) if(A[i][j]==3) return 0;
 
	for(int i=1; i<=N; i++) par[i]=i;
 
	for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) if(A[i][j]!=0) Union(i, j);
	for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) if(A[i][j]==0 && Find(i)==Find(j)) return 0;
 
	for(int i=1; i<=N; i++) V[Find(i)].push_back(i);
	for(int i=1; i<=N; i++) par[i]=i;
 
	for(int p=1; p<=N; p++)
	{
		if(V[p].empty()) continue;
		vector<int> &VV=V[p];
 
		for(int i=0; i<VV.size(); i++) for(int j=i+1; j<VV.size(); j++) if(A[VV[i]][VV[j]]==1) Union(VV[i], VV[j]);
		for(int i=0; i<VV.size(); i++) for(int j=i+1; j<VV.size(); j++) if(A[VV[i]][VV[j]]==2 && Find(VV[i])==Find(VV[j])) return 0;
		vector<int> cyc;
		for(auto it : VV)
		{
			if(par[it]==it) cyc.push_back(it);
			else addEdge(it, par[it]);
		}
		if(cyc.size()==2) return 0;
		if(cyc.size()==1) continue;
		for(int i=0; i+1<cyc.size(); i++) addEdge(cyc[i], cyc[i+1]);
		addEdge(cyc.back(), cyc[0]);
	}
 
	vector<vector<int>> ans2;
	ans2=vector<vector<int>>(N, vector<int>(N));
	for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) ans2[i-1][j-1]=ans[i][j];
	build(ans2);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:54:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int i=0; i<VV.size(); i++) for(int j=i+1; j<VV.size(); j++) if(A[VV[i]][VV[j]]==1) Union(VV[i], VV[j]);
      |                ~^~~~~~~~~~
supertrees.cpp:54:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int i=0; i<VV.size(); i++) for(int j=i+1; j<VV.size(); j++) if(A[VV[i]][VV[j]]==1) Union(VV[i], VV[j]);
      |                                                 ~^~~~~~~~~~
supertrees.cpp:55:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int i=0; i<VV.size(); i++) for(int j=i+1; j<VV.size(); j++) if(A[VV[i]][VV[j]]==2 && Find(VV[i])==Find(VV[j])) return 0;
      |                ~^~~~~~~~~~
supertrees.cpp:55:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int i=0; i<VV.size(); i++) for(int j=i+1; j<VV.size(); j++) if(A[VV[i]][VV[j]]==2 && Find(VV[i])==Find(VV[j])) return 0;
      |                                                 ~^~~~~~~~~~
supertrees.cpp:64:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   for(int i=0; i+1<cyc.size(); i++) addEdge(cyc[i], cyc[i+1]);
      |                ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 2816 KB Output is correct
7 Correct 274 ms 30196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 2816 KB Output is correct
7 Correct 274 ms 30196 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 246 ms 26204 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 416 KB Output is correct
16 Correct 6 ms 1408 KB Output is correct
17 Correct 119 ms 12144 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 63 ms 9592 KB Output is correct
21 Correct 250 ms 30200 KB Output is correct
22 Correct 245 ms 29688 KB Output is correct
23 Correct 280 ms 30072 KB Output is correct
24 Correct 247 ms 26360 KB Output is correct
25 Correct 101 ms 12152 KB Output is correct
26 Correct 95 ms 12152 KB Output is correct
27 Correct 282 ms 30072 KB Output is correct
28 Correct 246 ms 26360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 11 ms 2176 KB Output is correct
9 Correct 247 ms 26104 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 12 ms 2816 KB Output is correct
13 Correct 268 ms 30072 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1408 KB Output is correct
17 Correct 120 ms 12152 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 65 ms 9708 KB Output is correct
22 Correct 251 ms 30072 KB Output is correct
23 Correct 250 ms 30072 KB Output is correct
24 Correct 278 ms 30072 KB Output is correct
25 Correct 104 ms 12280 KB Output is correct
26 Correct 107 ms 12256 KB Output is correct
27 Correct 267 ms 30068 KB Output is correct
28 Correct 271 ms 30068 KB Output is correct
29 Correct 108 ms 12280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 64 ms 9596 KB Output is correct
5 Correct 270 ms 30200 KB Output is correct
6 Correct 246 ms 29688 KB Output is correct
7 Correct 272 ms 30072 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 64 ms 9720 KB Output is correct
10 Correct 251 ms 30072 KB Output is correct
11 Correct 248 ms 30072 KB Output is correct
12 Correct 274 ms 30108 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 64 ms 9676 KB Output is correct
17 Correct 259 ms 30072 KB Output is correct
18 Correct 250 ms 29816 KB Output is correct
19 Correct 244 ms 29688 KB Output is correct
20 Correct 247 ms 26288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 2816 KB Output is correct
7 Correct 274 ms 30196 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 246 ms 26204 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 416 KB Output is correct
16 Correct 6 ms 1408 KB Output is correct
17 Correct 119 ms 12144 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 63 ms 9592 KB Output is correct
21 Correct 250 ms 30200 KB Output is correct
22 Correct 245 ms 29688 KB Output is correct
23 Correct 280 ms 30072 KB Output is correct
24 Correct 247 ms 26360 KB Output is correct
25 Correct 101 ms 12152 KB Output is correct
26 Correct 95 ms 12152 KB Output is correct
27 Correct 282 ms 30072 KB Output is correct
28 Correct 246 ms 26360 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 2176 KB Output is correct
37 Correct 247 ms 26104 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 12 ms 2816 KB Output is correct
41 Correct 268 ms 30072 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 6 ms 1408 KB Output is correct
45 Correct 120 ms 12152 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 65 ms 9708 KB Output is correct
50 Correct 251 ms 30072 KB Output is correct
51 Correct 250 ms 30072 KB Output is correct
52 Correct 278 ms 30072 KB Output is correct
53 Correct 104 ms 12280 KB Output is correct
54 Correct 107 ms 12256 KB Output is correct
55 Correct 267 ms 30068 KB Output is correct
56 Correct 271 ms 30068 KB Output is correct
57 Correct 108 ms 12280 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 6 ms 1408 KB Output is correct
61 Correct 122 ms 12152 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 0 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 66 ms 9592 KB Output is correct
66 Correct 99 ms 12152 KB Output is correct
67 Correct 100 ms 12152 KB Output is correct
68 Correct 97 ms 12152 KB Output is correct
69 Correct 104 ms 12272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 12 ms 2816 KB Output is correct
7 Correct 274 ms 30196 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 246 ms 26204 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 416 KB Output is correct
16 Correct 6 ms 1408 KB Output is correct
17 Correct 119 ms 12144 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 63 ms 9592 KB Output is correct
21 Correct 250 ms 30200 KB Output is correct
22 Correct 245 ms 29688 KB Output is correct
23 Correct 280 ms 30072 KB Output is correct
24 Correct 247 ms 26360 KB Output is correct
25 Correct 101 ms 12152 KB Output is correct
26 Correct 95 ms 12152 KB Output is correct
27 Correct 282 ms 30072 KB Output is correct
28 Correct 246 ms 26360 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 2176 KB Output is correct
37 Correct 247 ms 26104 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 12 ms 2816 KB Output is correct
41 Correct 268 ms 30072 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 6 ms 1408 KB Output is correct
45 Correct 120 ms 12152 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 65 ms 9708 KB Output is correct
50 Correct 251 ms 30072 KB Output is correct
51 Correct 250 ms 30072 KB Output is correct
52 Correct 278 ms 30072 KB Output is correct
53 Correct 104 ms 12280 KB Output is correct
54 Correct 107 ms 12256 KB Output is correct
55 Correct 267 ms 30068 KB Output is correct
56 Correct 271 ms 30068 KB Output is correct
57 Correct 108 ms 12280 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 64 ms 9596 KB Output is correct
62 Correct 270 ms 30200 KB Output is correct
63 Correct 246 ms 29688 KB Output is correct
64 Correct 272 ms 30072 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 64 ms 9720 KB Output is correct
67 Correct 251 ms 30072 KB Output is correct
68 Correct 248 ms 30072 KB Output is correct
69 Correct 274 ms 30108 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 64 ms 9676 KB Output is correct
74 Correct 259 ms 30072 KB Output is correct
75 Correct 250 ms 29816 KB Output is correct
76 Correct 244 ms 29688 KB Output is correct
77 Correct 247 ms 26288 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 0 ms 384 KB Output is correct
80 Correct 6 ms 1408 KB Output is correct
81 Correct 122 ms 12152 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 0 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 66 ms 9592 KB Output is correct
86 Correct 99 ms 12152 KB Output is correct
87 Correct 100 ms 12152 KB Output is correct
88 Correct 97 ms 12152 KB Output is correct
89 Correct 104 ms 12272 KB Output is correct
90 Correct 0 ms 384 KB Output is correct
91 Correct 0 ms 384 KB Output is correct
92 Correct 7 ms 1536 KB Output is correct
93 Correct 111 ms 12148 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 0 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 24 ms 4384 KB Output is correct
98 Correct 96 ms 12152 KB Output is correct
99 Correct 97 ms 12152 KB Output is correct
100 Correct 100 ms 12152 KB Output is correct
101 Correct 93 ms 12144 KB Output is correct
102 Correct 116 ms 12152 KB Output is correct
103 Correct 116 ms 12280 KB Output is correct
104 Correct 115 ms 12152 KB Output is correct
105 Correct 110 ms 12144 KB Output is correct