Submission #526644

# Submission time Handle Problem Language Result Execution time Memory
526644 2022-02-15T19:53:56 Z Deepesson Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
219 ms 24120 KB
#include <bits/stdc++.h>
#include "supertrees.h"

///void build(std::vector<std::vector<int>> _b);

#define MAX 1005
int pai[MAX][10];
int find(int a,int b){
    if(pai[a][b]==a){
        return a;
    }
    return pai[a][b]=find(pai[a][b],b);
}
void Union(int a,int b,int c){
    a=find(a,c);
    b=find(b,c);
    pai[a][c]=b;
}
void ativar(int a,int b,std::vector<std::vector<int>>& ref){
    ref[a][b]=ref[b][a]=1;
   /// printf("Constroi %d %d\n",a,b);
}
int construct(std::vector<std::vector<int>> p) {
    std::vector<std::vector<int>> answer;
    int n = p.size();
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	for(int i=0;i!=10;++i){
        for(int j=0;j!=MAX;++j)
            pai[j][i]=j;
	}
    int N = p.size();
	bool emciclo[N]={};
    for(int i=0;i!=N;++i){
        if(!p[i][i])return 0;///Tem que ligar consigo mesmo
        for(int j=0;j!=N;++j){
            if(p[i][j]==3)return 0;///Impossivel 3 caminhos
            if(p[i][j]!=p[j][i])return 0;
            if(p[i][j]==2){///Em ciclo
                Union(i,j,1);
                emciclo[i]=emciclo[j]=1;
            }
            if(p[i][j]==1){///Conexao direta
                Union(i,j,4);
            }
            if(p[i][j]!=0){///Conectado
                Union(i,j,0);
            }
        }
    }
    ///Construir arvore
    {
        std::map<int,std::vector<int>> grupos;
        for(int i=0;i!=N;++i){
            grupos[find(i,4)].push_back(i);
        }
        for(auto&x:grupos){
            if(x.second.size()==1)continue;
            std::vector<int> copia;
            copia=x.second;
            for(int i=1;i<copia.size();++i){
                if(find(copia[0],7)==find(copia[i],7))return 0;
                    Union(copia[0],copia[i],7);
                    ativar(copia[i],copia[0],answer);
            }
        }
    }
  ///  printf("Arvores inauguradas!\n");
    ///Construir ciclos
    {
        std::map<int,std::vector<int>> grupos;
        for(int i=0;i!=N;++i){
            if(!emciclo[i])continue;
            if(find(i,7)!=i)continue;
            grupos[find(i,1)].push_back(i);
        }
        for(auto&x:grupos){
            if(x.second.size()<3)return 0;
            std::vector<int> copia;
            copia=x.second;
            for(int i=1;i<copia.size();++i){
                if(find(copia[i],7)==find(copia[i-1],7))return 0;
                Union(copia[i],copia[i-1],7);
                ativar(copia[i],copia[i-1],answer);
            }
            Union(copia[0],copia[copia.size()-1],7);
            ativar(copia[0],copia[copia.size()-1],answer);
        }
    }
    for(int i=0;i!=N;++i){
        for(int j=0;j!=N;++j){
            bool k = find(i,7)==find(j,7);
            bool u = p[i][j];
            if(k!=u)return 0;
        }
    }
    build(answer);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:64:26: 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=1;i<copia.size();++i){
      |                         ~^~~~~~~~~~~~~
supertrees.cpp:84:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |             for(int i=1;i<copia.size();++i){
      |                         ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 292 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 189 ms 22852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 292 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 189 ms 22852 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 280 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 7 ms 1228 KB Output is correct
13 Correct 170 ms 22748 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 5 ms 812 KB Output is correct
17 Correct 89 ms 14060 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 0 ms 336 KB Output is correct
20 Correct 43 ms 6260 KB Output is correct
21 Correct 184 ms 23972 KB Output is correct
22 Correct 208 ms 24060 KB Output is correct
23 Correct 217 ms 23932 KB Output is correct
24 Correct 185 ms 24120 KB Output is correct
25 Correct 73 ms 14084 KB Output is correct
26 Correct 67 ms 14068 KB Output is correct
27 Correct 207 ms 24064 KB Output is correct
28 Correct 202 ms 24004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 7 ms 1228 KB Output is correct
9 Correct 169 ms 22660 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 9 ms 1228 KB Output is correct
13 Correct 210 ms 22672 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 7 ms 816 KB Output is correct
17 Correct 93 ms 14204 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 45 ms 6256 KB Output is correct
22 Correct 182 ms 24052 KB Output is correct
23 Correct 173 ms 23980 KB Output is correct
24 Correct 213 ms 24048 KB Output is correct
25 Correct 68 ms 14200 KB Output is correct
26 Correct 84 ms 14320 KB Output is correct
27 Correct 169 ms 23980 KB Output is correct
28 Correct 189 ms 24048 KB Output is correct
29 Correct 69 ms 14196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 44 ms 6252 KB Output is correct
5 Correct 172 ms 22688 KB Output is correct
6 Correct 184 ms 22676 KB Output is correct
7 Correct 201 ms 22676 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 48 ms 6188 KB Output is correct
10 Correct 179 ms 22652 KB Output is correct
11 Correct 178 ms 22636 KB Output is correct
12 Correct 196 ms 22652 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 44 ms 6256 KB Output is correct
17 Correct 177 ms 22708 KB Output is correct
18 Correct 219 ms 22712 KB Output is correct
19 Correct 179 ms 22740 KB Output is correct
20 Correct 168 ms 22708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 292 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 189 ms 22852 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 280 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 7 ms 1228 KB Output is correct
13 Correct 170 ms 22748 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 5 ms 812 KB Output is correct
17 Correct 89 ms 14060 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 0 ms 336 KB Output is correct
20 Correct 43 ms 6260 KB Output is correct
21 Correct 184 ms 23972 KB Output is correct
22 Correct 208 ms 24060 KB Output is correct
23 Correct 217 ms 23932 KB Output is correct
24 Correct 185 ms 24120 KB Output is correct
25 Correct 73 ms 14084 KB Output is correct
26 Correct 67 ms 14068 KB Output is correct
27 Correct 207 ms 24064 KB Output is correct
28 Correct 202 ms 24004 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 7 ms 1228 KB Output is correct
37 Correct 169 ms 22660 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 9 ms 1228 KB Output is correct
41 Correct 210 ms 22672 KB Output is correct
42 Correct 0 ms 332 KB Output is correct
43 Correct 1 ms 292 KB Output is correct
44 Correct 7 ms 816 KB Output is correct
45 Correct 93 ms 14204 KB Output is correct
46 Correct 0 ms 332 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 45 ms 6256 KB Output is correct
50 Correct 182 ms 24052 KB Output is correct
51 Correct 173 ms 23980 KB Output is correct
52 Correct 213 ms 24048 KB Output is correct
53 Correct 68 ms 14200 KB Output is correct
54 Correct 84 ms 14320 KB Output is correct
55 Correct 169 ms 23980 KB Output is correct
56 Correct 189 ms 24048 KB Output is correct
57 Correct 69 ms 14196 KB Output is correct
58 Correct 0 ms 300 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 6 ms 884 KB Output is correct
61 Correct 98 ms 14068 KB Output is correct
62 Correct 0 ms 336 KB Output is correct
63 Correct 1 ms 336 KB Output is correct
64 Correct 0 ms 332 KB Output is correct
65 Correct 50 ms 6312 KB Output is correct
66 Correct 72 ms 14196 KB Output is correct
67 Correct 72 ms 14192 KB Output is correct
68 Correct 71 ms 14064 KB Output is correct
69 Correct 70 ms 14252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 292 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 8 ms 1228 KB Output is correct
7 Correct 189 ms 22852 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 280 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 7 ms 1228 KB Output is correct
13 Correct 170 ms 22748 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 5 ms 812 KB Output is correct
17 Correct 89 ms 14060 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 0 ms 336 KB Output is correct
20 Correct 43 ms 6260 KB Output is correct
21 Correct 184 ms 23972 KB Output is correct
22 Correct 208 ms 24060 KB Output is correct
23 Correct 217 ms 23932 KB Output is correct
24 Correct 185 ms 24120 KB Output is correct
25 Correct 73 ms 14084 KB Output is correct
26 Correct 67 ms 14068 KB Output is correct
27 Correct 207 ms 24064 KB Output is correct
28 Correct 202 ms 24004 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 7 ms 1228 KB Output is correct
37 Correct 169 ms 22660 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 9 ms 1228 KB Output is correct
41 Correct 210 ms 22672 KB Output is correct
42 Correct 0 ms 332 KB Output is correct
43 Correct 1 ms 292 KB Output is correct
44 Correct 7 ms 816 KB Output is correct
45 Correct 93 ms 14204 KB Output is correct
46 Correct 0 ms 332 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 45 ms 6256 KB Output is correct
50 Correct 182 ms 24052 KB Output is correct
51 Correct 173 ms 23980 KB Output is correct
52 Correct 213 ms 24048 KB Output is correct
53 Correct 68 ms 14200 KB Output is correct
54 Correct 84 ms 14320 KB Output is correct
55 Correct 169 ms 23980 KB Output is correct
56 Correct 189 ms 24048 KB Output is correct
57 Correct 69 ms 14196 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 0 ms 332 KB Output is correct
60 Correct 0 ms 332 KB Output is correct
61 Correct 44 ms 6252 KB Output is correct
62 Correct 172 ms 22688 KB Output is correct
63 Correct 184 ms 22676 KB Output is correct
64 Correct 201 ms 22676 KB Output is correct
65 Correct 0 ms 332 KB Output is correct
66 Correct 48 ms 6188 KB Output is correct
67 Correct 179 ms 22652 KB Output is correct
68 Correct 178 ms 22636 KB Output is correct
69 Correct 196 ms 22652 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 336 KB Output is correct
73 Correct 44 ms 6256 KB Output is correct
74 Correct 177 ms 22708 KB Output is correct
75 Correct 219 ms 22712 KB Output is correct
76 Correct 179 ms 22740 KB Output is correct
77 Correct 168 ms 22708 KB Output is correct
78 Correct 0 ms 300 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 6 ms 884 KB Output is correct
81 Correct 98 ms 14068 KB Output is correct
82 Correct 0 ms 336 KB Output is correct
83 Correct 1 ms 336 KB Output is correct
84 Correct 0 ms 332 KB Output is correct
85 Correct 50 ms 6312 KB Output is correct
86 Correct 72 ms 14196 KB Output is correct
87 Correct 72 ms 14192 KB Output is correct
88 Correct 71 ms 14064 KB Output is correct
89 Correct 70 ms 14252 KB Output is correct
90 Correct 0 ms 332 KB Output is correct
91 Correct 0 ms 300 KB Output is correct
92 Correct 4 ms 844 KB Output is correct
93 Correct 81 ms 14024 KB Output is correct
94 Correct 1 ms 332 KB Output is correct
95 Correct 1 ms 292 KB Output is correct
96 Correct 1 ms 332 KB Output is correct
97 Correct 19 ms 3700 KB Output is correct
98 Correct 71 ms 14080 KB Output is correct
99 Correct 66 ms 14020 KB Output is correct
100 Correct 64 ms 14020 KB Output is correct
101 Correct 65 ms 14120 KB Output is correct
102 Correct 67 ms 14064 KB Output is correct
103 Correct 70 ms 14124 KB Output is correct
104 Correct 67 ms 14084 KB Output is correct
105 Correct 77 ms 14068 KB Output is correct