답안 #653773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
653773 2022-10-28T04:28:43 Z coding_snorlax 슈퍼트리 잇기 (IOI20_supertrees) C++14
96 / 100
224 ms 23100 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
int Boss[1005];
int Rank[1005];
int query(int x){
    if(Boss[x]==x) return x;
    else return Boss[x]=query(Boss[x]);
}
int Union(int x,int y){
    int A1=query(x);
    int A2=query(y);
    if(A1==A2){
        return 0;
    }
    if (Rank[A1]>Rank[A2]) Boss[A2]=A1;
    else if(Rank[A1]<Rank[A2]) Boss[A1]=A2;
    else{
        Boss[A2]=A1;
        Rank[A1]++;
    }
    return 1;
}
int construct(vector<vector<int>> x){
    for(int i=0;i<1005;i++){
        Boss[i]=i;
        Rank[i]=0;
    }
    vector<vector<int>> built;
    for(int i=0;i<x.size();i++){
        vector<int> New;
        for(int j=0;j<x.size();j++){
            New.push_back(0);
        }
        built.push_back(New);
    }
    int check=0;
    for(int i=0;i<x.size();i++){
        for(int j=0;j<x.size();j++){
            if (x[i][j]) check=Union(i,j);
            }
        }
    int New_Boss[1005];
    for(int i=0;i<1005;i++){
        New_Boss[i]=query(i);
    }
    //renew Union set;
    for(int i=0;i<1005;i++){
        Boss[i]=i;
        Rank[i]=0;
    }
    vector<int> under_going={0};
    for(int i=0;i<(int)x.size();i++){
        for(int j=0;j<(int)x.size();j++){
            if(x[i][j]==1) Union(i,j);
        }
    }
    int now_Boss=New_Boss[0];
    int Mark[1005]={0};
    vector<int> tmp_List={0};
    vector<int> cycle[1005];
    for(int Time=0;Time<(int)x.size();Time++){
        if(!Mark[Time]){
            now_Boss=query(Time);
            cycle[New_Boss[Time]].push_back(Time);
            Mark[Time]=1;
            for(int i=0;i<(int)x.size();i++){
                if(now_Boss==query(i)&&Time!=i&&!Mark[i]){
                //must=1
                    Mark[i]=1;
                    if(query(i)==now_Boss){
                        built[i][now_Boss]=1;
                        built[now_Boss][i]=1;
                    }
                }
            }
        }
    }
    int answer=1;
    for(int i=0;i<1005;i++){
        if((int)cycle[i].size()>2){
            for(int j=0;j<(int)cycle[i].size()-1;j++){
                built[cycle[i][j]][cycle[i][j+1]]=1;
                built[cycle[i][j+1]][cycle[i][j]]=1;
            }
            built[cycle[i][0]][cycle[i][(int)cycle[i].size()-1]]=1;
            built[cycle[i][(int)cycle[i].size()-1]][cycle[i][0]]=1;
        }
        else{
            if((int)cycle[i].size()==2) answer=0;
        }
    }
    for(int i=0;i<(int)x.size();i++){
        for(int j=0;j<(int)x.size();j++){
            if(x[i][j]==2 && (!New_Boss[i]==New_Boss[j] || query(i)==query(j))) answer=0;
            if(x[i][j]==1 && (!New_Boss[i]==New_Boss[j] || !query(i)==query(j))) answer=0;
            if(x[i][j]==0 && (New_Boss[i]==New_Boss[j])) answer=0;
        }
    }
    if(answer) build(built);
    return answer;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i=0;i<x.size();i++){
      |                 ~^~~~~~~~~
supertrees.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int j=0;j<x.size();j++){
      |                     ~^~~~~~~~~
supertrees.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0;i<x.size();i++){
      |                 ~^~~~~~~~~
supertrees.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int j=0;j<x.size();j++){
      |                     ~^~~~~~~~~
supertrees.cpp:95:43: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
   95 |             if(x[i][j]==2 && (!New_Boss[i]==New_Boss[j] || query(i)==query(j))) answer=0;
      |                                           ^~
supertrees.cpp:95:31: note: add parentheses around left hand side expression to silence this warning
   95 |             if(x[i][j]==2 && (!New_Boss[i]==New_Boss[j] || query(i)==query(j))) answer=0;
      |                               ^~~~~~~~~~~~
      |                               (           )
supertrees.cpp:96:43: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
   96 |             if(x[i][j]==1 && (!New_Boss[i]==New_Boss[j] || !query(i)==query(j))) answer=0;
      |                                           ^~
supertrees.cpp:96:31: note: add parentheses around left hand side expression to silence this warning
   96 |             if(x[i][j]==1 && (!New_Boss[i]==New_Boss[j] || !query(i)==query(j))) answer=0;
      |                               ^~~~~~~~~~~~
      |                               (           )
supertrees.cpp:96:69: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
   96 |             if(x[i][j]==1 && (!New_Boss[i]==New_Boss[j] || !query(i)==query(j))) answer=0;
      |                                                                     ^~
supertrees.cpp:96:60: note: add parentheses around left hand side expression to silence this warning
   96 |             if(x[i][j]==1 && (!New_Boss[i]==New_Boss[j] || !query(i)==query(j))) answer=0;
      |                                                            ^~~~~~~~~
      |                                                            (        )
supertrees.cpp:37:9: warning: variable 'check' set but not used [-Wunused-but-set-variable]
   37 |     int check=0;
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1172 KB Output is correct
7 Correct 187 ms 22024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1172 KB Output is correct
7 Correct 187 ms 22024 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1200 KB Output is correct
13 Correct 172 ms 22052 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 110 ms 12296 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 49 ms 5812 KB Output is correct
21 Correct 183 ms 22036 KB Output is correct
22 Correct 174 ms 22028 KB Output is correct
23 Correct 191 ms 22020 KB Output is correct
24 Correct 185 ms 22004 KB Output is correct
25 Correct 77 ms 12172 KB Output is correct
26 Correct 78 ms 12164 KB Output is correct
27 Correct 198 ms 22024 KB Output is correct
28 Correct 172 ms 22056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 8 ms 1236 KB Output is correct
9 Correct 182 ms 23100 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 1208 KB Output is correct
13 Correct 181 ms 22628 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 105 ms 12724 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 63 ms 6240 KB Output is correct
22 Correct 178 ms 22616 KB Output is correct
23 Correct 212 ms 22640 KB Output is correct
24 Correct 192 ms 22732 KB Output is correct
25 Correct 102 ms 12728 KB Output is correct
26 Correct 80 ms 12664 KB Output is correct
27 Correct 179 ms 22608 KB Output is correct
28 Correct 224 ms 22636 KB Output is correct
29 Correct 81 ms 12784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 45 ms 5864 KB Output is correct
5 Correct 179 ms 22060 KB Output is correct
6 Correct 176 ms 22092 KB Output is correct
7 Correct 213 ms 22036 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 50 ms 5760 KB Output is correct
10 Correct 175 ms 22052 KB Output is correct
11 Correct 194 ms 22092 KB Output is correct
12 Correct 196 ms 22056 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 47 ms 5708 KB Output is correct
17 Correct 178 ms 22072 KB Output is correct
18 Correct 186 ms 22040 KB Output is correct
19 Correct 169 ms 22008 KB Output is correct
20 Correct 185 ms 22036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1172 KB Output is correct
7 Correct 187 ms 22024 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1200 KB Output is correct
13 Correct 172 ms 22052 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 110 ms 12296 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 49 ms 5812 KB Output is correct
21 Correct 183 ms 22036 KB Output is correct
22 Correct 174 ms 22028 KB Output is correct
23 Correct 191 ms 22020 KB Output is correct
24 Correct 185 ms 22004 KB Output is correct
25 Correct 77 ms 12172 KB Output is correct
26 Correct 78 ms 12164 KB Output is correct
27 Correct 198 ms 22024 KB Output is correct
28 Correct 172 ms 22056 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1236 KB Output is correct
37 Correct 182 ms 23100 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 9 ms 1208 KB Output is correct
41 Correct 181 ms 22628 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 5 ms 852 KB Output is correct
45 Correct 105 ms 12724 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 63 ms 6240 KB Output is correct
50 Correct 178 ms 22616 KB Output is correct
51 Correct 212 ms 22640 KB Output is correct
52 Correct 192 ms 22732 KB Output is correct
53 Correct 102 ms 12728 KB Output is correct
54 Correct 80 ms 12664 KB Output is correct
55 Correct 179 ms 22608 KB Output is correct
56 Correct 224 ms 22636 KB Output is correct
57 Correct 81 ms 12784 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 5 ms 832 KB Output is correct
61 Correct 104 ms 14140 KB Output is correct
62 Correct 1 ms 312 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 56 ms 6264 KB Output is correct
66 Correct 80 ms 14084 KB Output is correct
67 Correct 81 ms 14072 KB Output is correct
68 Correct 93 ms 14068 KB Output is correct
69 Correct 83 ms 14084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1172 KB Output is correct
7 Correct 187 ms 22024 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1200 KB Output is correct
13 Correct 172 ms 22052 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 110 ms 12296 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 49 ms 5812 KB Output is correct
21 Correct 183 ms 22036 KB Output is correct
22 Correct 174 ms 22028 KB Output is correct
23 Correct 191 ms 22020 KB Output is correct
24 Correct 185 ms 22004 KB Output is correct
25 Correct 77 ms 12172 KB Output is correct
26 Correct 78 ms 12164 KB Output is correct
27 Correct 198 ms 22024 KB Output is correct
28 Correct 172 ms 22056 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1236 KB Output is correct
37 Correct 182 ms 23100 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 9 ms 1208 KB Output is correct
41 Correct 181 ms 22628 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 5 ms 852 KB Output is correct
45 Correct 105 ms 12724 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 63 ms 6240 KB Output is correct
50 Correct 178 ms 22616 KB Output is correct
51 Correct 212 ms 22640 KB Output is correct
52 Correct 192 ms 22732 KB Output is correct
53 Correct 102 ms 12728 KB Output is correct
54 Correct 80 ms 12664 KB Output is correct
55 Correct 179 ms 22608 KB Output is correct
56 Correct 224 ms 22636 KB Output is correct
57 Correct 81 ms 12784 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 45 ms 5864 KB Output is correct
62 Correct 179 ms 22060 KB Output is correct
63 Correct 176 ms 22092 KB Output is correct
64 Correct 213 ms 22036 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 50 ms 5760 KB Output is correct
67 Correct 175 ms 22052 KB Output is correct
68 Correct 194 ms 22092 KB Output is correct
69 Correct 196 ms 22056 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 47 ms 5708 KB Output is correct
74 Correct 178 ms 22072 KB Output is correct
75 Correct 186 ms 22040 KB Output is correct
76 Correct 169 ms 22008 KB Output is correct
77 Correct 185 ms 22036 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 5 ms 832 KB Output is correct
81 Correct 104 ms 14140 KB Output is correct
82 Correct 1 ms 312 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 56 ms 6264 KB Output is correct
86 Correct 80 ms 14084 KB Output is correct
87 Correct 81 ms 14072 KB Output is correct
88 Correct 93 ms 14068 KB Output is correct
89 Correct 83 ms 14084 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 0 ms 340 KB Output is correct
92 Correct 5 ms 852 KB Output is correct
93 Correct 98 ms 14080 KB Output is correct
94 Incorrect 1 ms 340 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -