Submission #1007388

# Submission time Handle Problem Language Result Execution time Memory
1007388 2024-06-24T18:36:40 Z Ahmed57 Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
149 ms 24152 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(p[i][j]){
                mergegroup(i,j);
            }
        }
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            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(p[i][j]==1){
                mergegroup2(i,j);
            }
        }
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            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;
                }
            }
            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:99:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |                 for(int e = 1;e<ror[j].size();e++){
      |                               ~^~~~~~~~~~~~~~
supertrees.cpp:104:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |             for(int j = 0;j<nah.size();j++){
      |                           ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 6 ms 1424 KB Output is correct
7 Correct 122 ms 24040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 6 ms 1424 KB Output is correct
7 Correct 122 ms 24040 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 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 149 ms 24008 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 62 ms 14096 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 32 ms 6276 KB Output is correct
21 Correct 115 ms 24064 KB Output is correct
22 Correct 119 ms 24148 KB Output is correct
23 Correct 129 ms 24148 KB Output is correct
24 Correct 119 ms 24148 KB Output is correct
25 Correct 52 ms 14100 KB Output is correct
26 Correct 69 ms 14164 KB Output is correct
27 Correct 129 ms 23952 KB Output is correct
28 Correct 119 ms 24152 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 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 444 KB Output is correct
4 Correct 34 ms 6412 KB Output is correct
5 Correct 129 ms 24148 KB Output is correct
6 Correct 115 ms 24152 KB Output is correct
7 Correct 130 ms 24148 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 30 ms 6228 KB Output is correct
10 Correct 142 ms 24148 KB Output is correct
11 Correct 117 ms 24084 KB Output is correct
12 Correct 116 ms 24152 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 45 ms 6416 KB Output is correct
17 Correct 115 ms 24072 KB Output is correct
18 Correct 128 ms 24148 KB Output is correct
19 Correct 115 ms 24148 KB Output is correct
20 Correct 126 ms 24148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 6 ms 1424 KB Output is correct
7 Correct 122 ms 24040 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 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 149 ms 24008 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 62 ms 14096 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 32 ms 6276 KB Output is correct
21 Correct 115 ms 24064 KB Output is correct
22 Correct 119 ms 24148 KB Output is correct
23 Correct 129 ms 24148 KB Output is correct
24 Correct 119 ms 24148 KB Output is correct
25 Correct 52 ms 14100 KB Output is correct
26 Correct 69 ms 14164 KB Output is correct
27 Correct 129 ms 23952 KB Output is correct
28 Correct 119 ms 24152 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 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 6 ms 1424 KB Output is correct
7 Correct 122 ms 24040 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 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 149 ms 24008 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 62 ms 14096 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 32 ms 6276 KB Output is correct
21 Correct 115 ms 24064 KB Output is correct
22 Correct 119 ms 24148 KB Output is correct
23 Correct 129 ms 24148 KB Output is correct
24 Correct 119 ms 24148 KB Output is correct
25 Correct 52 ms 14100 KB Output is correct
26 Correct 69 ms 14164 KB Output is correct
27 Correct 129 ms 23952 KB Output is correct
28 Correct 119 ms 24152 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 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -