Submission #384930

# Submission time Handle Problem Language Result Execution time Memory
384930 2021-04-02T16:49:38 Z Ahmadsm2005 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
265 ms 30572 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
int N,edges[1001][1001],GRP[1001],Z,FAIL,GRP2[1001],Z2;
vector<vector<int>>ALL;
vector<vector<int>>P;
void CONNECT2(vector<int>X){
for(int i=1;i<X.size();i++){
edges[X[i]][X[i-1]]=1,edges[X[i-1]][X[i]]=1;
}
}
void CONNECT(vector<int>X){
vector<vector<int>>CYCLE;
for(int i=0;i<X.size();i++){
vector<int>TEMP;
if(GRP2[X[i]]+1)
continue;
TEMP.push_back(X[i]);
GRP2[X[i]]=Z2;
for(int l=0;l<N;l++){
if(P[X[i]][l]==1&&X[i]!=l){
if(GRP2[l]+1){
FAIL=1;
return;
}
TEMP.push_back(l),GRP2[l]=Z2;
}
}
for(int l=0;l<TEMP.size();l++){
int CNT=0;
for(int x=0;x<TEMP.size();x++){
if(l!=x&&(P[TEMP[l]][TEMP[x]]!=1)){
FAIL=1;
return;
}
}
for(int x=0;x<N;x++)
if(P[TEMP[l]][x]==1)
CNT++;
if(CNT!=TEMP.size()){
FAIL=1;
return;
}
}
CYCLE.push_back(TEMP);
Z2++;
}
if(CYCLE.size()==2){
FAIL=1;
return;
}
for(int i=1;i<CYCLE.size();i++)
edges[CYCLE[i][0]][CYCLE[i-1][0]]=1,edges[CYCLE[i-1][0]][CYCLE[i][0]]=1;
if(CYCLE.size()>2)
edges[CYCLE.back()[0]][CYCLE[0][0]]=1,edges[CYCLE[0][0]][CYCLE.back()[0]]=1;
for(int i=0;i<CYCLE.size();i++)
CONNECT2(CYCLE[i]);
}
int construct(std::vector<std::vector<int>>p){
N=p.size();
P=p;
for(int i=0;i<N;i++)
for(int l=0;l<N;l++)
if(p[i][l]==3)
return 0;
for(int i=0;i<1001;i++)
GRP[i]=-1,GRP2[i]=-1;
for(int i=0;i<N;i++){
vector<int>TEMP;
if(GRP[i]+1)
continue;
TEMP.push_back(i);
GRP[i]=Z;
for(int l=0;l<N;l++){
if(p[i][l]&&i!=l){
if(GRP[l]+1)
return 0;
TEMP.push_back(l),GRP[l]=Z;
}
}
for(int l=0;l<TEMP.size();l++){
int CNT=0;
for(int x=0;x<TEMP.size();x++){
if(l!=x&&(!p[TEMP[l]][TEMP[x]]))
return 0;
}
for(int x=0;x<N;x++)
if(p[TEMP[l]][x])
CNT++;
if(CNT!=TEMP.size())
return 0;
}
ALL.push_back(TEMP);
Z++;
}
for(int i=0;i<ALL.size();i++)
CONNECT(ALL[i]);
vector<vector<int>>ANS;
for(int i=0;i<N;i++){
vector<int>FF;
for(int l=0;l<N;l++)
FF.push_back(edges[i][l]);
ANS.push_back(FF);
}
if(FAIL)
return 0;
build(ANS);
return 1;
}

Compilation message

supertrees.cpp: In function 'void CONNECT2(std::vector<int>)':
supertrees.cpp:8:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | for(int i=1;i<X.size();i++){
      |             ~^~~~~~~~~
supertrees.cpp: In function 'void CONNECT(std::vector<int>)':
supertrees.cpp:14:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 | for(int i=0;i<X.size();i++){
      |             ~^~~~~~~~~
supertrees.cpp:29:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 | for(int l=0;l<TEMP.size();l++){
      |             ~^~~~~~~~~~~~
supertrees.cpp:31:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 | for(int x=0;x<TEMP.size();x++){
      |             ~^~~~~~~~~~~~
supertrees.cpp:40:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 | if(CNT!=TEMP.size()){
      |    ~~~^~~~~~~~~~~~~
supertrees.cpp:52:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 | for(int i=1;i<CYCLE.size();i++)
      |             ~^~~~~~~~~~~~~
supertrees.cpp:56:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 | for(int i=0;i<CYCLE.size();i++)
      |             ~^~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:81:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 | for(int l=0;l<TEMP.size();l++){
      |             ~^~~~~~~~~~~~
supertrees.cpp:83:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 | for(int x=0;x<TEMP.size();x++){
      |             ~^~~~~~~~~~~~
supertrees.cpp:90:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 | if(CNT!=TEMP.size())
      |    ~~~^~~~~~~~~~~~~
supertrees.cpp:96:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 | for(int i=0;i<ALL.size();i++)
      |             ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 2156 KB Output is correct
7 Correct 249 ms 30060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 2156 KB Output is correct
7 Correct 249 ms 30060 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 12 ms 1388 KB Output is correct
13 Correct 261 ms 26092 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 114 ms 12140 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 65 ms 8684 KB Output is correct
21 Correct 256 ms 30060 KB Output is correct
22 Correct 264 ms 29548 KB Output is correct
23 Correct 260 ms 30060 KB Output is correct
24 Correct 262 ms 26348 KB Output is correct
25 Correct 105 ms 12140 KB Output is correct
26 Correct 100 ms 12140 KB Output is correct
27 Correct 265 ms 29932 KB Output is correct
28 Correct 263 ms 26348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 12 ms 1388 KB Output is correct
9 Correct 261 ms 26220 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 12 ms 2156 KB Output is correct
13 Correct 250 ms 29932 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 103 ms 12140 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 66 ms 8704 KB Output is correct
22 Correct 261 ms 30060 KB Output is correct
23 Correct 260 ms 30060 KB Output is correct
24 Correct 258 ms 29932 KB Output is correct
25 Correct 114 ms 16492 KB Output is correct
26 Correct 101 ms 12140 KB Output is correct
27 Correct 256 ms 30060 KB Output is correct
28 Correct 260 ms 30444 KB Output is correct
29 Correct 119 ms 16876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 67 ms 9068 KB Output is correct
5 Correct 256 ms 30572 KB Output is correct
6 Correct 256 ms 29932 KB Output is correct
7 Correct 261 ms 30316 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 66 ms 9068 KB Output is correct
10 Correct 259 ms 30444 KB Output is correct
11 Correct 257 ms 30316 KB Output is correct
12 Correct 258 ms 30316 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 68 ms 9068 KB Output is correct
17 Correct 258 ms 30444 KB Output is correct
18 Correct 262 ms 30316 KB Output is correct
19 Correct 255 ms 30316 KB Output is correct
20 Correct 262 ms 26732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 2156 KB Output is correct
7 Correct 249 ms 30060 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 12 ms 1388 KB Output is correct
13 Correct 261 ms 26092 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 114 ms 12140 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 65 ms 8684 KB Output is correct
21 Correct 256 ms 30060 KB Output is correct
22 Correct 264 ms 29548 KB Output is correct
23 Correct 260 ms 30060 KB Output is correct
24 Correct 262 ms 26348 KB Output is correct
25 Correct 105 ms 12140 KB Output is correct
26 Correct 100 ms 12140 KB Output is correct
27 Correct 265 ms 29932 KB Output is correct
28 Correct 263 ms 26348 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 12 ms 1388 KB Output is correct
37 Correct 261 ms 26220 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 12 ms 2156 KB Output is correct
41 Correct 250 ms 29932 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 5 ms 876 KB Output is correct
45 Correct 103 ms 12140 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 2 ms 364 KB Output is correct
49 Correct 66 ms 8704 KB Output is correct
50 Correct 261 ms 30060 KB Output is correct
51 Correct 260 ms 30060 KB Output is correct
52 Correct 258 ms 29932 KB Output is correct
53 Correct 114 ms 16492 KB Output is correct
54 Correct 101 ms 12140 KB Output is correct
55 Correct 256 ms 30060 KB Output is correct
56 Correct 260 ms 30444 KB Output is correct
57 Correct 119 ms 16876 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 5 ms 876 KB Output is correct
61 Correct 102 ms 12524 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 68 ms 9068 KB Output is correct
66 Correct 100 ms 12524 KB Output is correct
67 Correct 103 ms 12524 KB Output is correct
68 Correct 100 ms 12524 KB Output is correct
69 Correct 118 ms 16876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 2156 KB Output is correct
7 Correct 249 ms 30060 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 12 ms 1388 KB Output is correct
13 Correct 261 ms 26092 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 114 ms 12140 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 65 ms 8684 KB Output is correct
21 Correct 256 ms 30060 KB Output is correct
22 Correct 264 ms 29548 KB Output is correct
23 Correct 260 ms 30060 KB Output is correct
24 Correct 262 ms 26348 KB Output is correct
25 Correct 105 ms 12140 KB Output is correct
26 Correct 100 ms 12140 KB Output is correct
27 Correct 265 ms 29932 KB Output is correct
28 Correct 263 ms 26348 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 12 ms 1388 KB Output is correct
37 Correct 261 ms 26220 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 12 ms 2156 KB Output is correct
41 Correct 250 ms 29932 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 5 ms 876 KB Output is correct
45 Correct 103 ms 12140 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 2 ms 364 KB Output is correct
49 Correct 66 ms 8704 KB Output is correct
50 Correct 261 ms 30060 KB Output is correct
51 Correct 260 ms 30060 KB Output is correct
52 Correct 258 ms 29932 KB Output is correct
53 Correct 114 ms 16492 KB Output is correct
54 Correct 101 ms 12140 KB Output is correct
55 Correct 256 ms 30060 KB Output is correct
56 Correct 260 ms 30444 KB Output is correct
57 Correct 119 ms 16876 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 67 ms 9068 KB Output is correct
62 Correct 256 ms 30572 KB Output is correct
63 Correct 256 ms 29932 KB Output is correct
64 Correct 261 ms 30316 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 66 ms 9068 KB Output is correct
67 Correct 259 ms 30444 KB Output is correct
68 Correct 257 ms 30316 KB Output is correct
69 Correct 258 ms 30316 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 68 ms 9068 KB Output is correct
74 Correct 258 ms 30444 KB Output is correct
75 Correct 262 ms 30316 KB Output is correct
76 Correct 255 ms 30316 KB Output is correct
77 Correct 262 ms 26732 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 5 ms 876 KB Output is correct
81 Correct 102 ms 12524 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 68 ms 9068 KB Output is correct
86 Correct 100 ms 12524 KB Output is correct
87 Correct 103 ms 12524 KB Output is correct
88 Correct 100 ms 12524 KB Output is correct
89 Correct 118 ms 16876 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 5 ms 876 KB Output is correct
93 Correct 97 ms 12672 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 26 ms 3820 KB Output is correct
98 Correct 101 ms 14188 KB Output is correct
99 Correct 101 ms 14172 KB Output is correct
100 Correct 102 ms 14188 KB Output is correct
101 Correct 100 ms 14188 KB Output is correct
102 Correct 96 ms 14188 KB Output is correct
103 Correct 92 ms 14188 KB Output is correct
104 Correct 100 ms 14188 KB Output is correct
105 Correct 102 ms 14188 KB Output is correct