Submission #619715

# Submission time Handle Problem Language Result Execution time Memory
619715 2022-08-02T14:56:56 Z mosiashvililuka Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
293 ms 30448 KB
#include<bits/stdc++.h>
#include "supertrees.h"
#include <vector>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,f[1009][1009],msh[1009],zm[1009],bo[1009][1009],p[1009],pi,MSH[1009],ZM[1009];
vector <int> v[1009],V[1009];
vector <vector <int> > ANS;
int fnd(int q){
    if(msh[q]==0) return q; else return msh[q]=fnd(msh[q]);
}
void mrg(int q, int w){
    q=fnd(q);w=fnd(w);
    if(q==w) return;
    if(zm[q]<zm[w]) swap(q,w);
    msh[w]=q;
    if(zm[q]==zm[w]) zm[q]++;
}





int FND(int q){
    if(MSH[q]==0) return q; else return MSH[q]=fnd(MSH[q]);
}
void MRG(int q, int w){
    q=FND(q);w=FND(w);
    if(q==w) return;
    if(ZM[q]<ZM[w]) swap(q,w);
    MSH[w]=q;
    if(ZM[q]==ZM[w]) ZM[q]++;
}
int construct(vector <vector <int> > Pp) {
    a=Pp.size();
    for(i=1; i<=a; i++){
        for(j=1; j<=a; j++){
            f[i][j]=Pp[i-1][j-1];
            if(f[i][j]==3) return 0;
        }
    }
    //check

    for(i=1; i<=a; i++){
        for(j=i+1; j<=a; j++){
            if(f[i][j]!=0) mrg(i,j);
        }
    }
    for(i=1; i<=a; i++){
        for(j=i+1; j<=a; j++){
            if(fnd(i)==fnd(j)){
                if(f[i][j]==0) return 0;
            }
        }
    }
    for(i=0; i<=a+1; i++){
        msh[i]=zm[i]=0;
    }

    //
    for(i=1; i<=a; i++){
        for(j=i+1; j<=a; j++){
            if(f[i][j]==1) mrg(i,j);
        }
    }
    for(i=1; i<=a; i++){
        v[fnd(i)].push_back(i);
    }
    for(i=1; i<=a; i++){
        for(ii=0; ii<v[i].size(); ii++){
            for(jj=ii+1; jj<v[i].size(); jj++){
                c=v[i][ii];d=v[i][jj];
                if(f[c][d]!=1) return 0;
            }
        }
    }
    for(i=1; i<=a; i++){
        if(v[i].size()==0) continue;
        for(jj=1; jj<v[i].size(); jj++){
            c=v[i][jj-1];d=v[i][jj];
            bo[c][d]=bo[d][c]=1;
        }
        pi++;p[pi]=v[i][0];
    }
    for(i=1; i<=pi; i++){
        for(j=i+1; j<=pi; j++){
            if(f[p[i]][p[j]]==2) MRG(p[i],p[j]);
        }
    }
    for(i=1; i<=pi; i++){
        V[FND(p[i])].push_back(p[i]);
    }
    for(i=1; i<=a; i++){
        if(V[i].size()==2) return 0;
        if(V[i].size()<=1) continue;
        for(ii=0; ii<V[i].size(); ii++){
            for(jj=ii+1; jj<V[i].size(); jj++){
                c=V[i][ii];d=V[i][jj];
                if(f[c][d]!=2) return 0;
            }
        }
        for(jj=0; jj<V[i].size(); jj++){
            if(jj!=0) c=V[i][jj-1]; else c=V[i][V[i].size()-1];
            d=V[i][jj];
            bo[c][d]=bo[d][c]=1;
        }
    }
    ANS.resize(a);
    for(i=0; i<a; i++) ANS[i].resize(a);
    for(i=0; i<a; i++){
        for(j=0; j<a; j++){
            ANS[i][j]=bo[i+1][j+1];
        }
    }
    build(ANS);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:69:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for(ii=0; ii<v[i].size(); ii++){
      |                   ~~^~~~~~~~~~~~
supertrees.cpp:70:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for(jj=ii+1; jj<v[i].size(); jj++){
      |                          ~~^~~~~~~~~~~~
supertrees.cpp:78:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |         for(jj=1; jj<v[i].size(); jj++){
      |                   ~~^~~~~~~~~~~~
supertrees.cpp:95:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |         for(ii=0; ii<V[i].size(); ii++){
      |                   ~~^~~~~~~~~~~~
supertrees.cpp:96:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |             for(jj=ii+1; jj<V[i].size(); jj++){
      |                          ~~^~~~~~~~~~~~
supertrees.cpp:101:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for(jj=0; jj<V[i].size(); jj++){
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 356 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 2900 KB Output is correct
7 Correct 189 ms 30360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 356 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 2900 KB Output is correct
7 Correct 189 ms 30360 KB Output is correct
8 Correct 1 ms 388 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 360 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 8 ms 2132 KB Output is correct
13 Correct 196 ms 26416 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 1492 KB Output is correct
17 Correct 82 ms 12556 KB Output is correct
18 Correct 1 ms 352 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 52 ms 10004 KB Output is correct
21 Correct 179 ms 30396 KB Output is correct
22 Correct 184 ms 29880 KB Output is correct
23 Correct 218 ms 30348 KB Output is correct
24 Correct 211 ms 26668 KB Output is correct
25 Correct 71 ms 12580 KB Output is correct
26 Correct 74 ms 12584 KB Output is correct
27 Correct 197 ms 30448 KB Output is correct
28 Correct 293 ms 26732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 380 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 356 KB Output is correct
4 Correct 1 ms 360 KB Output is correct
5 Correct 1 ms 404 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 10 ms 2132 KB Output is correct
9 Correct 191 ms 26520 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 356 KB Output is correct
12 Correct 9 ms 2900 KB Output is correct
13 Correct 195 ms 30348 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 1492 KB Output is correct
17 Correct 86 ms 12584 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 356 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 48 ms 9932 KB Output is correct
22 Correct 192 ms 30420 KB Output is correct
23 Correct 207 ms 30344 KB Output is correct
24 Correct 204 ms 30360 KB Output is correct
25 Correct 97 ms 12876 KB Output is correct
26 Correct 75 ms 12460 KB Output is correct
27 Correct 184 ms 30348 KB Output is correct
28 Correct 217 ms 30412 KB Output is correct
29 Correct 77 ms 12860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 356 KB Output is correct
4 Correct 65 ms 9944 KB Output is correct
5 Correct 190 ms 30300 KB Output is correct
6 Correct 239 ms 29900 KB Output is correct
7 Correct 199 ms 30312 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 67 ms 9952 KB Output is correct
10 Correct 186 ms 30388 KB Output is correct
11 Correct 202 ms 30396 KB Output is correct
12 Correct 195 ms 30388 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 360 KB Output is correct
16 Correct 49 ms 10060 KB Output is correct
17 Correct 226 ms 30360 KB Output is correct
18 Correct 265 ms 30256 KB Output is correct
19 Correct 194 ms 30336 KB Output is correct
20 Correct 182 ms 26676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 356 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 2900 KB Output is correct
7 Correct 189 ms 30360 KB Output is correct
8 Correct 1 ms 388 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 360 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 8 ms 2132 KB Output is correct
13 Correct 196 ms 26416 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 1492 KB Output is correct
17 Correct 82 ms 12556 KB Output is correct
18 Correct 1 ms 352 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 52 ms 10004 KB Output is correct
21 Correct 179 ms 30396 KB Output is correct
22 Correct 184 ms 29880 KB Output is correct
23 Correct 218 ms 30348 KB Output is correct
24 Correct 211 ms 26668 KB Output is correct
25 Correct 71 ms 12580 KB Output is correct
26 Correct 74 ms 12584 KB Output is correct
27 Correct 197 ms 30448 KB Output is correct
28 Correct 293 ms 26732 KB Output is correct
29 Correct 1 ms 380 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 356 KB Output is correct
32 Correct 1 ms 360 KB Output is correct
33 Correct 1 ms 404 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 10 ms 2132 KB Output is correct
37 Correct 191 ms 26520 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 356 KB Output is correct
40 Correct 9 ms 2900 KB Output is correct
41 Correct 195 ms 30348 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 1492 KB Output is correct
45 Correct 86 ms 12584 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 356 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 48 ms 9932 KB Output is correct
50 Correct 192 ms 30420 KB Output is correct
51 Correct 207 ms 30344 KB Output is correct
52 Correct 204 ms 30360 KB Output is correct
53 Correct 97 ms 12876 KB Output is correct
54 Correct 75 ms 12460 KB Output is correct
55 Correct 184 ms 30348 KB Output is correct
56 Correct 217 ms 30412 KB Output is correct
57 Correct 77 ms 12860 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 4 ms 1516 KB Output is correct
61 Correct 87 ms 12572 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 59 ms 10036 KB Output is correct
66 Correct 92 ms 12452 KB Output is correct
67 Correct 83 ms 12560 KB Output is correct
68 Correct 81 ms 12464 KB Output is correct
69 Correct 79 ms 12800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 356 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 2900 KB Output is correct
7 Correct 189 ms 30360 KB Output is correct
8 Correct 1 ms 388 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 360 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 8 ms 2132 KB Output is correct
13 Correct 196 ms 26416 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 4 ms 1492 KB Output is correct
17 Correct 82 ms 12556 KB Output is correct
18 Correct 1 ms 352 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 52 ms 10004 KB Output is correct
21 Correct 179 ms 30396 KB Output is correct
22 Correct 184 ms 29880 KB Output is correct
23 Correct 218 ms 30348 KB Output is correct
24 Correct 211 ms 26668 KB Output is correct
25 Correct 71 ms 12580 KB Output is correct
26 Correct 74 ms 12584 KB Output is correct
27 Correct 197 ms 30448 KB Output is correct
28 Correct 293 ms 26732 KB Output is correct
29 Correct 1 ms 380 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 356 KB Output is correct
32 Correct 1 ms 360 KB Output is correct
33 Correct 1 ms 404 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 10 ms 2132 KB Output is correct
37 Correct 191 ms 26520 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 356 KB Output is correct
40 Correct 9 ms 2900 KB Output is correct
41 Correct 195 ms 30348 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 1492 KB Output is correct
45 Correct 86 ms 12584 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 356 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 48 ms 9932 KB Output is correct
50 Correct 192 ms 30420 KB Output is correct
51 Correct 207 ms 30344 KB Output is correct
52 Correct 204 ms 30360 KB Output is correct
53 Correct 97 ms 12876 KB Output is correct
54 Correct 75 ms 12460 KB Output is correct
55 Correct 184 ms 30348 KB Output is correct
56 Correct 217 ms 30412 KB Output is correct
57 Correct 77 ms 12860 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 356 KB Output is correct
61 Correct 65 ms 9944 KB Output is correct
62 Correct 190 ms 30300 KB Output is correct
63 Correct 239 ms 29900 KB Output is correct
64 Correct 199 ms 30312 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 67 ms 9952 KB Output is correct
67 Correct 186 ms 30388 KB Output is correct
68 Correct 202 ms 30396 KB Output is correct
69 Correct 195 ms 30388 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 0 ms 340 KB Output is correct
72 Correct 1 ms 360 KB Output is correct
73 Correct 49 ms 10060 KB Output is correct
74 Correct 226 ms 30360 KB Output is correct
75 Correct 265 ms 30256 KB Output is correct
76 Correct 194 ms 30336 KB Output is correct
77 Correct 182 ms 26676 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 4 ms 1516 KB Output is correct
81 Correct 87 ms 12572 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 59 ms 10036 KB Output is correct
86 Correct 92 ms 12452 KB Output is correct
87 Correct 83 ms 12560 KB Output is correct
88 Correct 81 ms 12464 KB Output is correct
89 Correct 79 ms 12800 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 0 ms 340 KB Output is correct
92 Correct 3 ms 724 KB Output is correct
93 Correct 82 ms 8504 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 28 ms 2820 KB Output is correct
98 Correct 88 ms 8764 KB Output is correct
99 Correct 122 ms 9124 KB Output is correct
100 Correct 70 ms 8892 KB Output is correct
101 Correct 82 ms 9928 KB Output is correct
102 Correct 68 ms 8508 KB Output is correct
103 Correct 71 ms 8584 KB Output is correct
104 Correct 74 ms 8508 KB Output is correct
105 Correct 80 ms 8524 KB Output is correct