Submission #586057

# Submission time Handle Problem Language Result Execution time Memory
586057 2022-06-29T19:06:13 Z John3_141592 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
194 ms 26796 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

int dad[1006],ded[1006],asd[1003][1003];

int Find(int x){
    return x==dad[x]?x:dad[x]=Find(dad[x]);
}

void Union(int a,int b){
    a=Find(a),b=Find(b);
    if(a>b) swap(a,b);
    dad[b]=a;
}

int Find1(int x){
    return x==ded[x]?x:ded[x]=Find1(ded[x]);
}

void Union1(int a,int b){
    a=Find1(a),b=Find1(b);
    if(a>b) swap(a,b);
    ded[b]=a;
}

int construct(std::vector<std::vector<int>> p) {
	int n=p.size();
	vector <vector <int> > answer;
	bool band=false,BAND=false,FLAG=false;
	for(int i=0;i<=n;i++) dad[i]=i;
	for(int i=0;i<n;i++){
        for(int j=0;j<p[i].size();j++){
            if(p[i][j]==3) FLAG=true;
            if(p[i][j]==2) band=true;
            else if(i!=j && p[i][j]) BAND=true;
            if(p[i][j]) Union(i,j);
        }
	}
	for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j && p[i][j]!=1) return 0;
            if(!p[i][j] && Find(i)==Find(j)) return 0;
        }
	}
	if(FLAG){
        return 0;
	}else if(!band){
        memset(asd,0,sizeof(asd));
        for(int i=0;i<n;i++){
            if(i==Find(i)) continue;
            asd[i][Find(i)]=asd[Find(i)][i]=1;
        }
        for(int i=0;i<n;i++){
            vector <int> qwe;
            for(int j=0;j<n;j++){
                qwe.push_back(asd[i][j]);
            }
            answer.push_back(qwe);
        }
	}else if(!BAND){
        vector <int> grafo[1000];
        for(int i=0;i<n;i++){
            grafo[Find(i)].push_back(i);
        }
        bool flag=false;
        for(int i=0;i<n;i++){
            if(grafo[i].empty()) continue;
            int v=grafo[i].size();
            if(v==2) return 0;
            for(int j=0;j<v;j++) asd[grafo[i][(j-1+v)%v]][grafo[i][j]]=asd[grafo[i][j]][grafo[i][(j-1+v)%v]]=1;
        }
        for(int i=0;i<n;i++){
            vector <int> qwe;
            for(int j=0;j<n;j++){
                if(i==j) qwe.push_back(0);
                else qwe.push_back(asd[i][j]);
            }
            answer.push_back(qwe);
        }
	}else{
        for(int i=0;i<=n;i++) ded[i]=i;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(p[i][j]==1){
                    Union1(i,j);
                }
            }
        }
        vector <int> grafo[1000];
        for(int i=0;i<n;i++){
            grafo[Find1(i)].push_back(i);
        }
        for(int i=0;i<n;i++){
            if(grafo[i].empty()) continue;
            int v=grafo[i].size();
            for(int j=0;j<v;j++) asd[i][grafo[i][j]]=asd[grafo[i][j]][i]=1;
        }
        vector <int> qwe;
        for(int i=0;i<n;i++){
            if(grafo[i].empty()) continue;
            qwe.push_back(i);
        }
        for(int i=0;i<n;i++) grafo[i].clear();
        for(auto i:qwe) grafo[Find(i)].push_back(i);
        for(int i=0;i<n;i++){
            if(grafo[i].empty()) continue;
            int v=grafo[i].size();
            if(v==2) return 0;
            for(int j=0;j<v;j++) asd[grafo[i][(j-1+v)%v]][grafo[i][j]]=asd[grafo[i][j]][grafo[i][(j-1+v)%v]]=1;
        }
        for(int i=0;i<n;i++){
            vector <int> qwe;
            for(int j=0;j<n;j++){
                if(i==j) qwe.push_back(0);
                else qwe.push_back(asd[i][j]);
            }
            answer.push_back(qwe);
        }
	}
	build(answer);
	return 1;
}



//#include "supertrees.h"
//#include <vector>
//
//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);
//	}
//	build(answer);
//	return 1;
//}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int j=0;j<p[i].size();j++){
      |                     ~^~~~~~~~~~~~
supertrees.cpp:67:14: warning: unused variable 'flag' [-Wunused-variable]
   67 |         bool flag=false;
      |              ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Correct 2 ms 4180 KB Output is correct
6 Correct 9 ms 5108 KB Output is correct
7 Correct 179 ms 25996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Correct 2 ms 4180 KB Output is correct
6 Correct 9 ms 5108 KB Output is correct
7 Correct 179 ms 25996 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 2 ms 4180 KB Output is correct
10 Correct 2 ms 4180 KB Output is correct
11 Correct 2 ms 4180 KB Output is correct
12 Correct 10 ms 5076 KB Output is correct
13 Correct 169 ms 26140 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 88 ms 8228 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 46 ms 9676 KB Output is correct
21 Correct 179 ms 25972 KB Output is correct
22 Correct 178 ms 26016 KB Output is correct
23 Correct 189 ms 25948 KB Output is correct
24 Correct 174 ms 25972 KB Output is correct
25 Correct 79 ms 8204 KB Output is correct
26 Correct 68 ms 8204 KB Output is correct
27 Correct 186 ms 25944 KB Output is correct
28 Correct 168 ms 26012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 4148 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 9 ms 5164 KB Output is correct
9 Correct 169 ms 26700 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 8 ms 1992 KB Output is correct
13 Correct 182 ms 26772 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 680 KB Output is correct
17 Correct 101 ms 8884 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 45 ms 8212 KB Output is correct
22 Correct 180 ms 26796 KB Output is correct
23 Correct 181 ms 26688 KB Output is correct
24 Correct 194 ms 26772 KB Output is correct
25 Correct 74 ms 11276 KB Output is correct
26 Correct 73 ms 8932 KB Output is correct
27 Correct 175 ms 26768 KB Output is correct
28 Correct 192 ms 26692 KB Output is correct
29 Correct 72 ms 11268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 50 ms 9616 KB Output is correct
5 Correct 182 ms 26000 KB Output is correct
6 Correct 172 ms 25996 KB Output is correct
7 Correct 191 ms 26004 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 46 ms 7700 KB Output is correct
10 Correct 177 ms 26748 KB Output is correct
11 Correct 169 ms 26652 KB Output is correct
12 Correct 187 ms 26716 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 46 ms 8132 KB Output is correct
17 Correct 173 ms 26432 KB Output is correct
18 Correct 186 ms 26096 KB Output is correct
19 Correct 171 ms 26188 KB Output is correct
20 Correct 172 ms 26424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Correct 2 ms 4180 KB Output is correct
6 Correct 9 ms 5108 KB Output is correct
7 Correct 179 ms 25996 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 2 ms 4180 KB Output is correct
10 Correct 2 ms 4180 KB Output is correct
11 Correct 2 ms 4180 KB Output is correct
12 Correct 10 ms 5076 KB Output is correct
13 Correct 169 ms 26140 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 88 ms 8228 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 46 ms 9676 KB Output is correct
21 Correct 179 ms 25972 KB Output is correct
22 Correct 178 ms 26016 KB Output is correct
23 Correct 189 ms 25948 KB Output is correct
24 Correct 174 ms 25972 KB Output is correct
25 Correct 79 ms 8204 KB Output is correct
26 Correct 68 ms 8204 KB Output is correct
27 Correct 186 ms 25944 KB Output is correct
28 Correct 168 ms 26012 KB Output is correct
29 Correct 2 ms 4180 KB Output is correct
30 Correct 2 ms 4180 KB Output is correct
31 Correct 2 ms 4180 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 4148 KB Output is correct
35 Correct 2 ms 4180 KB Output is correct
36 Correct 9 ms 5164 KB Output is correct
37 Correct 169 ms 26700 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 8 ms 1992 KB Output is correct
41 Correct 182 ms 26772 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 680 KB Output is correct
45 Correct 101 ms 8884 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 45 ms 8212 KB Output is correct
50 Correct 180 ms 26796 KB Output is correct
51 Correct 181 ms 26688 KB Output is correct
52 Correct 194 ms 26772 KB Output is correct
53 Correct 74 ms 11276 KB Output is correct
54 Correct 73 ms 8932 KB Output is correct
55 Correct 175 ms 26768 KB Output is correct
56 Correct 192 ms 26692 KB Output is correct
57 Correct 72 ms 11268 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 4 ms 724 KB Output is correct
61 Correct 92 ms 8900 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 45 ms 8140 KB Output is correct
66 Correct 69 ms 8688 KB Output is correct
67 Correct 79 ms 8832 KB Output is correct
68 Correct 70 ms 8692 KB Output is correct
69 Correct 72 ms 12620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4180 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4180 KB Output is correct
5 Correct 2 ms 4180 KB Output is correct
6 Correct 9 ms 5108 KB Output is correct
7 Correct 179 ms 25996 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 2 ms 4180 KB Output is correct
10 Correct 2 ms 4180 KB Output is correct
11 Correct 2 ms 4180 KB Output is correct
12 Correct 10 ms 5076 KB Output is correct
13 Correct 169 ms 26140 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 88 ms 8228 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 46 ms 9676 KB Output is correct
21 Correct 179 ms 25972 KB Output is correct
22 Correct 178 ms 26016 KB Output is correct
23 Correct 189 ms 25948 KB Output is correct
24 Correct 174 ms 25972 KB Output is correct
25 Correct 79 ms 8204 KB Output is correct
26 Correct 68 ms 8204 KB Output is correct
27 Correct 186 ms 25944 KB Output is correct
28 Correct 168 ms 26012 KB Output is correct
29 Correct 2 ms 4180 KB Output is correct
30 Correct 2 ms 4180 KB Output is correct
31 Correct 2 ms 4180 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 4148 KB Output is correct
35 Correct 2 ms 4180 KB Output is correct
36 Correct 9 ms 5164 KB Output is correct
37 Correct 169 ms 26700 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 8 ms 1992 KB Output is correct
41 Correct 182 ms 26772 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 680 KB Output is correct
45 Correct 101 ms 8884 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 45 ms 8212 KB Output is correct
50 Correct 180 ms 26796 KB Output is correct
51 Correct 181 ms 26688 KB Output is correct
52 Correct 194 ms 26772 KB Output is correct
53 Correct 74 ms 11276 KB Output is correct
54 Correct 73 ms 8932 KB Output is correct
55 Correct 175 ms 26768 KB Output is correct
56 Correct 192 ms 26692 KB Output is correct
57 Correct 72 ms 11268 KB Output is correct
58 Correct 2 ms 4180 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 2 ms 4180 KB Output is correct
61 Correct 50 ms 9616 KB Output is correct
62 Correct 182 ms 26000 KB Output is correct
63 Correct 172 ms 25996 KB Output is correct
64 Correct 191 ms 26004 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 46 ms 7700 KB Output is correct
67 Correct 177 ms 26748 KB Output is correct
68 Correct 169 ms 26652 KB Output is correct
69 Correct 187 ms 26716 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 46 ms 8132 KB Output is correct
74 Correct 173 ms 26432 KB Output is correct
75 Correct 186 ms 26096 KB Output is correct
76 Correct 171 ms 26188 KB Output is correct
77 Correct 172 ms 26424 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 4 ms 724 KB Output is correct
81 Correct 92 ms 8900 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 45 ms 8140 KB Output is correct
86 Correct 69 ms 8688 KB Output is correct
87 Correct 79 ms 8832 KB Output is correct
88 Correct 70 ms 8692 KB Output is correct
89 Correct 72 ms 12620 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 4 ms 724 KB Output is correct
93 Correct 90 ms 8668 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 0 ms 340 KB Output is correct
97 Correct 18 ms 2632 KB Output is correct
98 Correct 70 ms 8652 KB Output is correct
99 Correct 70 ms 8612 KB Output is correct
100 Correct 73 ms 8632 KB Output is correct
101 Correct 79 ms 8744 KB Output is correct
102 Correct 82 ms 8652 KB Output is correct
103 Correct 108 ms 10168 KB Output is correct
104 Correct 88 ms 10124 KB Output is correct
105 Correct 84 ms 10108 KB Output is correct