Submission #1007395

# Submission time Handle Problem Language Result Execution time Memory
1007395 2024-06-24T18:55:36 Z Ahmed57 Connecting Supertrees (IOI20_supertrees) C++17
96 / 100
166 ms 24200 KB
#include "bits/stdc++.h"
#include "supertrees.h"

using namespace std;
int pr[100001];
int find(int x){
    if(x==pr[x])return x;
    return pr[x] = find(pr[x]);
}
void mergegroup(int a,int b){
    a = find(a);
    b = find(b);
    if(a==b)return ;
    pr[a] = b;
}
int pr2[100001];
int find2(int x){
    if(x==pr2[x])return x;
    return pr2[x] = find2(pr2[x]);
}
void mergegroup2(int a,int b){
    a = find2(a);
    b = find2(b);
    if(a==b)return ;
    pr2[a] = b;
}
int construct(vector<vector<int>> p){
    int n = p.size();
    vector<vector<int>> B;
    vector<int> x(n,0);
    for(int i = 0;i<n;i++){
        B.push_back(x);
    }
    //phase 1
    for(int i = 0;i<n;i++){
        pr[i] = i;
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            if(i==j)continue;
            if(p[i][j]){
                mergegroup(i,j);
            }
        }
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            if(i==j)continue;
            if(find(i)==find(j)){
                if(p[i][j]==0){
                    return 0;
                }
            }else{
                if(p[i][j]){
                    return 0;
                }
            }
        }
    }
    //phase 2
    for(int i = 0;i<n;i++){
        pr2[i] = i;
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            if(i==j)continue;
            if(p[i][j]==1){
                mergegroup2(i,j);
            }
        }
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            if(i==j)continue;
            if(find2(i)==find2(j)){
                if(p[i][j]!=1){
                    return 0;
                }
            }else{
                if(p[i][j]==1){
                    return 0;
                }
            }
        }
    }
    for(int i = 0;i<n;i++){
        if(i==find(i)){
            vector<int> lol;
            for(int j = 0;j<n;j++){
                if(find(i)==find(j)){
                    lol.push_back(j);
                }
            }
            vector<int> ror[n];
            for(int j:lol){
                ror[find2(j)].push_back(j);
            }
            vector<int> nah;
            for(int j = 0;j<n;j++){
                if(ror[j].size()){
                    nah.push_back(j);
                }
                for(int e = 1;e<ror[j].size();e++){
                    B[ror[j][e-1]][ror[j][e]]=1;
                    B[ror[j][e]][ror[j][e-1]]=1;
                }
            }
            if(nah.size()==2){
                return 0;
            }
            for(int j = 0;j<nah.size();j++){
                int a = nah[j] , b = nah[(j+1)%nah.size()];
                B[a][b] = 1;
                B[b][a] = 1;
            }
        }
    }
    for(int i = 0;i<n;i++)B[i][i] = 0;
    build(B);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:103:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |                 for(int e = 1;e<ror[j].size();e++){
      |                               ~^~~~~~~~~~~~~~
supertrees.cpp:111:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |             for(int j = 0;j<nah.size();j++){
      |                           ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1112 KB Output is correct
7 Correct 106 ms 22048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1112 KB Output is correct
7 Correct 106 ms 22048 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 125 ms 22044 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 66 ms 12068 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 5880 KB Output is correct
21 Correct 119 ms 22096 KB Output is correct
22 Correct 118 ms 22100 KB Output is correct
23 Correct 123 ms 22096 KB Output is correct
24 Correct 140 ms 22100 KB Output is correct
25 Correct 56 ms 12368 KB Output is correct
26 Correct 48 ms 12112 KB Output is correct
27 Correct 131 ms 22052 KB Output is correct
28 Correct 136 ms 22104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1204 KB Output is correct
9 Correct 154 ms 24084 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 116 ms 24200 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 63 ms 14216 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 30 ms 6228 KB Output is correct
22 Correct 113 ms 24148 KB Output is correct
23 Correct 111 ms 24148 KB Output is correct
24 Correct 166 ms 24140 KB Output is correct
25 Correct 80 ms 14164 KB Output is correct
26 Correct 51 ms 14224 KB Output is correct
27 Correct 159 ms 24104 KB Output is correct
28 Correct 121 ms 24148 KB Output is correct
29 Correct 61 ms 14164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 30 ms 5692 KB Output is correct
5 Correct 119 ms 22044 KB Output is correct
6 Correct 119 ms 22096 KB Output is correct
7 Correct 123 ms 22096 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 29 ms 5712 KB Output is correct
10 Correct 114 ms 22096 KB Output is correct
11 Correct 140 ms 22096 KB Output is correct
12 Correct 136 ms 22048 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 30 ms 5748 KB Output is correct
17 Correct 116 ms 22048 KB Output is correct
18 Correct 116 ms 22100 KB Output is correct
19 Correct 116 ms 22048 KB Output is correct
20 Correct 113 ms 22100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1112 KB Output is correct
7 Correct 106 ms 22048 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 125 ms 22044 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 66 ms 12068 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 5880 KB Output is correct
21 Correct 119 ms 22096 KB Output is correct
22 Correct 118 ms 22100 KB Output is correct
23 Correct 123 ms 22096 KB Output is correct
24 Correct 140 ms 22100 KB Output is correct
25 Correct 56 ms 12368 KB Output is correct
26 Correct 48 ms 12112 KB Output is correct
27 Correct 131 ms 22052 KB Output is correct
28 Correct 136 ms 22104 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1204 KB Output is correct
37 Correct 154 ms 24084 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1372 KB Output is correct
41 Correct 116 ms 24200 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 63 ms 14216 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 30 ms 6228 KB Output is correct
50 Correct 113 ms 24148 KB Output is correct
51 Correct 111 ms 24148 KB Output is correct
52 Correct 166 ms 24140 KB Output is correct
53 Correct 80 ms 14164 KB Output is correct
54 Correct 51 ms 14224 KB Output is correct
55 Correct 159 ms 24104 KB Output is correct
56 Correct 121 ms 24148 KB Output is correct
57 Correct 61 ms 14164 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 2 ms 860 KB Output is correct
61 Correct 57 ms 14016 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 31 ms 6356 KB Output is correct
66 Correct 55 ms 14228 KB Output is correct
67 Correct 51 ms 14164 KB Output is correct
68 Correct 103 ms 14168 KB Output is correct
69 Correct 57 ms 14216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 5 ms 1112 KB Output is correct
7 Correct 106 ms 22048 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 125 ms 22044 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 66 ms 12068 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 5880 KB Output is correct
21 Correct 119 ms 22096 KB Output is correct
22 Correct 118 ms 22100 KB Output is correct
23 Correct 123 ms 22096 KB Output is correct
24 Correct 140 ms 22100 KB Output is correct
25 Correct 56 ms 12368 KB Output is correct
26 Correct 48 ms 12112 KB Output is correct
27 Correct 131 ms 22052 KB Output is correct
28 Correct 136 ms 22104 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1204 KB Output is correct
37 Correct 154 ms 24084 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 5 ms 1372 KB Output is correct
41 Correct 116 ms 24200 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 63 ms 14216 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 30 ms 6228 KB Output is correct
50 Correct 113 ms 24148 KB Output is correct
51 Correct 111 ms 24148 KB Output is correct
52 Correct 166 ms 24140 KB Output is correct
53 Correct 80 ms 14164 KB Output is correct
54 Correct 51 ms 14224 KB Output is correct
55 Correct 159 ms 24104 KB Output is correct
56 Correct 121 ms 24148 KB Output is correct
57 Correct 61 ms 14164 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 30 ms 5692 KB Output is correct
62 Correct 119 ms 22044 KB Output is correct
63 Correct 119 ms 22096 KB Output is correct
64 Correct 123 ms 22096 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 29 ms 5712 KB Output is correct
67 Correct 114 ms 22096 KB Output is correct
68 Correct 140 ms 22096 KB Output is correct
69 Correct 136 ms 22048 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 30 ms 5748 KB Output is correct
74 Correct 116 ms 22048 KB Output is correct
75 Correct 116 ms 22100 KB Output is correct
76 Correct 116 ms 22048 KB Output is correct
77 Correct 113 ms 22100 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 2 ms 860 KB Output is correct
81 Correct 57 ms 14016 KB Output is correct
82 Correct 1 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 31 ms 6356 KB Output is correct
86 Correct 55 ms 14228 KB Output is correct
87 Correct 51 ms 14164 KB Output is correct
88 Correct 103 ms 14168 KB Output is correct
89 Correct 57 ms 14216 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 2 ms 860 KB Output is correct
93 Correct 54 ms 14008 KB Output is correct
94 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -