답안 #1007394

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007394 2024-06-24T18:51:29 Z Ahmed57 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
131 ms 22348 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;
                }
            }
            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:108:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |             for(int j = 0;j<nah.size();j++){
      |                           ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 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 1116 KB Output is correct
7 Correct 119 ms 22024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 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 1116 KB Output is correct
7 Correct 119 ms 22024 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 127 ms 22052 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 54 ms 12068 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5736 KB Output is correct
21 Correct 115 ms 22100 KB Output is correct
22 Correct 109 ms 22096 KB Output is correct
23 Correct 122 ms 22048 KB Output is correct
24 Correct 131 ms 22096 KB Output is correct
25 Correct 47 ms 12116 KB Output is correct
26 Correct 45 ms 12052 KB Output is correct
27 Correct 119 ms 22096 KB Output is correct
28 Correct 110 ms 22048 KB Output is correct
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 26 ms 5792 KB Output is correct
5 Correct 108 ms 22052 KB Output is correct
6 Correct 115 ms 22096 KB Output is correct
7 Correct 119 ms 22348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 27 ms 5692 KB Output is correct
10 Correct 106 ms 22100 KB Output is correct
11 Correct 104 ms 22100 KB Output is correct
12 Correct 110 ms 22100 KB Output is correct
13 Correct 0 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 29 ms 5756 KB Output is correct
17 Correct 113 ms 22100 KB Output is correct
18 Correct 105 ms 22100 KB Output is correct
19 Correct 108 ms 22100 KB Output is correct
20 Correct 116 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 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 1116 KB Output is correct
7 Correct 119 ms 22024 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 127 ms 22052 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 54 ms 12068 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5736 KB Output is correct
21 Correct 115 ms 22100 KB Output is correct
22 Correct 109 ms 22096 KB Output is correct
23 Correct 122 ms 22048 KB Output is correct
24 Correct 131 ms 22096 KB Output is correct
25 Correct 47 ms 12116 KB Output is correct
26 Correct 45 ms 12052 KB Output is correct
27 Correct 119 ms 22096 KB Output is correct
28 Correct 110 ms 22048 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 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 1116 KB Output is correct
7 Correct 119 ms 22024 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 127 ms 22052 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 54 ms 12068 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 5736 KB Output is correct
21 Correct 115 ms 22100 KB Output is correct
22 Correct 109 ms 22096 KB Output is correct
23 Correct 122 ms 22048 KB Output is correct
24 Correct 131 ms 22096 KB Output is correct
25 Correct 47 ms 12116 KB Output is correct
26 Correct 45 ms 12052 KB Output is correct
27 Correct 119 ms 22096 KB Output is correct
28 Correct 110 ms 22048 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 -