Submission #403791

# Submission time Handle Problem Language Result Execution time Memory
403791 2021-05-13T13:04:04 Z victoriad Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
280 ms 26552 KB
#include "supertrees.h"
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;


int construct(std::vector<std::vector<int> > p) {
	int n = p.size();
	vector<vector<int> >r(n);
	vector<vector<int> >c;
    vector<int>us(n,-1);
    int cc=0;
    vector<vector<int> >co;
    vector<int>u(n,-1);
    int aa=0;
    for(int i=0;i<n;i++){
        if(u[i]==-1){
            vector<int>s=p[i];
            co.push_back(s);
            for(int k=0;k<n;k++){
                if(s[k]!=0){
                    if(u[k]==-1){
                        u[k]=aa;
                    }
                    else if(u[k]!=aa){
                        return 0;
                        break;
                    }
                }
            }
            aa++;
        }
        else{
            int x=u[i];
            for(int k=0;k<n;k++){
                if(co[x][k]==p[i][k])continue;
                else{
                    if(co[x][k]==0 && p[i][k]!=0){
                        return 0;
                        break;
                    }
                    if(co[x][k]!=0 && p[i][k]==0){
                        return 0;
                        break;
                    }
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int k=0;k<n;k++){
            if(p[k][i]!=p[i][k]||p[k][i]==3){
                return 0;
                break;
            }
        }
    }
    for(int i=0;i<n;i++){
        if(p[i][i]!=1){
            return 0;
            break;
        }
        if(us[i]==-1){
            vector<int>s=p[i];
            vector<int>u;
            for(int k=0;k<n;k++){
                if(s[k]!=0){
                    if(us[k]==-1){
                    us[k]=cc;
                    u.push_back(k);
                    }
                    else{
                        return 0;
                        break;
                    }
                }
            }
            c.push_back(u);
            cc++;
        }
    }
    vector<int>a(n,0);
    for(int i=0;i<n;i++)r[i]=a;
    int pa=0;
    for(int i=0;i<n;i++){
        for(int k=0;k<n;k++){
            if(p[i][k]!=0 && us[i]!=us[k]){
                return 0;
                break;
            }
        }
    }
    for(int i=0;i<c.size();i++){
        vector<int>padre(n,-1);
        vector<int>raiz;
        for(int k=0;k<c[i].size();k++){
            if(padre[c[i][k]]==-1){
                padre[c[i][k]]=c[i][k];
                pa=c[i][k];
                int x=pa;
                raiz.push_back(pa);
                vector<int>s=p[c[i][k]];
                for(int j=0;j<n;j++){
            
                    if(p[c[i][k]][j]==1){
                        if(p[j]!=s){
                            return 0;
                            break;
                        }
                        if(j!=c[i][k] && padre[j]!=-1){
                            return 0;
                            break;
                        }
                        padre[j]=pa;
                        r[x][j]=1;
                        r[j][x]=1;
                        x=j;
                    }
                }
            }
        }
        int x=-1;
        if(raiz.size()==2){
            return 0;
        }
        for(int k=0;k<raiz.size();k++){
            if(x==-1){
                x=raiz[k];
            }
            else{
                r[x][raiz[k]]=1;
                r[raiz[k]][x]=1;
                x=raiz[k];
            }
        }
        if(x!=raiz[0]){
            r[raiz[0]][x]=1;
            r[x][raiz[0]]=1;
        }


    }
    for(int i=0;i<n;i++)r[i][i]=0;
    
    build(r);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:94:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for(int i=0;i<c.size();i++){
      |                 ~^~~~~~~~~
supertrees.cpp:97:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |         for(int k=0;k<c[i].size();k++){
      |                     ~^~~~~~~~~~~~
supertrees.cpp:127:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |         for(int k=0;k<raiz.size();k++){
      |                     ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1148 KB Output is correct
7 Correct 231 ms 22496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1148 KB Output is correct
7 Correct 231 ms 22496 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1356 KB Output is correct
13 Correct 241 ms 26552 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 588 KB Output is correct
17 Correct 110 ms 8640 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 64 ms 6132 KB Output is correct
21 Correct 238 ms 22300 KB Output is correct
22 Correct 249 ms 23804 KB Output is correct
23 Correct 246 ms 22252 KB Output is correct
24 Correct 250 ms 25996 KB Output is correct
25 Correct 103 ms 8388 KB Output is correct
26 Correct 102 ms 9240 KB Output is correct
27 Correct 239 ms 22308 KB Output is correct
28 Correct 267 ms 26012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 240 KB Output is correct
5 Correct 1 ms 280 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 11 ms 1356 KB Output is correct
9 Correct 280 ms 26440 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1220 KB Output is correct
13 Correct 255 ms 22516 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 588 KB Output is correct
17 Correct 118 ms 8700 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 61 ms 6340 KB Output is correct
22 Correct 239 ms 23920 KB Output is correct
23 Correct 262 ms 24800 KB Output is correct
24 Correct 244 ms 24016 KB Output is correct
25 Correct 126 ms 17888 KB Output is correct
26 Correct 107 ms 10088 KB Output is correct
27 Correct 245 ms 24800 KB Output is correct
28 Correct 246 ms 23896 KB Output is correct
29 Correct 116 ms 17888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 61 ms 6372 KB Output is correct
5 Correct 246 ms 22500 KB Output is correct
6 Correct 237 ms 24064 KB Output is correct
7 Correct 242 ms 22592 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 75 ms 6360 KB Output is correct
10 Correct 245 ms 22592 KB Output is correct
11 Correct 243 ms 23304 KB Output is correct
12 Correct 243 ms 22508 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 280 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 60 ms 6396 KB Output is correct
17 Correct 247 ms 22636 KB Output is correct
18 Correct 243 ms 22492 KB Output is correct
19 Correct 243 ms 22700 KB Output is correct
20 Correct 250 ms 26476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1148 KB Output is correct
7 Correct 231 ms 22496 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1356 KB Output is correct
13 Correct 241 ms 26552 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 588 KB Output is correct
17 Correct 110 ms 8640 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 64 ms 6132 KB Output is correct
21 Correct 238 ms 22300 KB Output is correct
22 Correct 249 ms 23804 KB Output is correct
23 Correct 246 ms 22252 KB Output is correct
24 Correct 250 ms 25996 KB Output is correct
25 Correct 103 ms 8388 KB Output is correct
26 Correct 102 ms 9240 KB Output is correct
27 Correct 239 ms 22308 KB Output is correct
28 Correct 267 ms 26012 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 240 KB Output is correct
33 Correct 1 ms 280 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 11 ms 1356 KB Output is correct
37 Correct 280 ms 26440 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 10 ms 1220 KB Output is correct
41 Correct 255 ms 22516 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 588 KB Output is correct
45 Correct 118 ms 8700 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 61 ms 6340 KB Output is correct
50 Correct 239 ms 23920 KB Output is correct
51 Correct 262 ms 24800 KB Output is correct
52 Correct 244 ms 24016 KB Output is correct
53 Correct 126 ms 17888 KB Output is correct
54 Correct 107 ms 10088 KB Output is correct
55 Correct 245 ms 24800 KB Output is correct
56 Correct 246 ms 23896 KB Output is correct
57 Correct 116 ms 17888 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 6 ms 672 KB Output is correct
61 Correct 113 ms 10076 KB Output is correct
62 Correct 1 ms 276 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 73 ms 6416 KB Output is correct
66 Correct 106 ms 10096 KB Output is correct
67 Correct 102 ms 10180 KB Output is correct
68 Correct 114 ms 10232 KB Output is correct
69 Correct 112 ms 17908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 10 ms 1148 KB Output is correct
7 Correct 231 ms 22496 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1356 KB Output is correct
13 Correct 241 ms 26552 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 588 KB Output is correct
17 Correct 110 ms 8640 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 64 ms 6132 KB Output is correct
21 Correct 238 ms 22300 KB Output is correct
22 Correct 249 ms 23804 KB Output is correct
23 Correct 246 ms 22252 KB Output is correct
24 Correct 250 ms 25996 KB Output is correct
25 Correct 103 ms 8388 KB Output is correct
26 Correct 102 ms 9240 KB Output is correct
27 Correct 239 ms 22308 KB Output is correct
28 Correct 267 ms 26012 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 240 KB Output is correct
33 Correct 1 ms 280 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 11 ms 1356 KB Output is correct
37 Correct 280 ms 26440 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 10 ms 1220 KB Output is correct
41 Correct 255 ms 22516 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 588 KB Output is correct
45 Correct 118 ms 8700 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 61 ms 6340 KB Output is correct
50 Correct 239 ms 23920 KB Output is correct
51 Correct 262 ms 24800 KB Output is correct
52 Correct 244 ms 24016 KB Output is correct
53 Correct 126 ms 17888 KB Output is correct
54 Correct 107 ms 10088 KB Output is correct
55 Correct 245 ms 24800 KB Output is correct
56 Correct 246 ms 23896 KB Output is correct
57 Correct 116 ms 17888 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 61 ms 6372 KB Output is correct
62 Correct 246 ms 22500 KB Output is correct
63 Correct 237 ms 24064 KB Output is correct
64 Correct 242 ms 22592 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 75 ms 6360 KB Output is correct
67 Correct 245 ms 22592 KB Output is correct
68 Correct 243 ms 23304 KB Output is correct
69 Correct 243 ms 22508 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 280 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 60 ms 6396 KB Output is correct
74 Correct 247 ms 22636 KB Output is correct
75 Correct 243 ms 22492 KB Output is correct
76 Correct 243 ms 22700 KB Output is correct
77 Correct 250 ms 26476 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 6 ms 672 KB Output is correct
81 Correct 113 ms 10076 KB Output is correct
82 Correct 1 ms 276 KB Output is correct
83 Correct 1 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 73 ms 6416 KB Output is correct
86 Correct 106 ms 10096 KB Output is correct
87 Correct 102 ms 10180 KB Output is correct
88 Correct 114 ms 10232 KB Output is correct
89 Correct 112 ms 17908 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 5 ms 588 KB Output is correct
93 Correct 106 ms 10084 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 31 ms 2772 KB Output is correct
98 Correct 112 ms 10076 KB Output is correct
99 Correct 112 ms 10084 KB Output is correct
100 Correct 105 ms 10308 KB Output is correct
101 Correct 105 ms 13924 KB Output is correct
102 Correct 103 ms 10096 KB Output is correct
103 Correct 115 ms 10132 KB Output is correct
104 Correct 108 ms 10088 KB Output is correct
105 Correct 109 ms 10052 KB Output is correct