답안 #615791

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
615791 2022-07-31T12:39:37 Z Iwanttobreakfree 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
244 ms 24052 KB
#include "supertrees.h"
#include <vector>
#include <iostream>
using namespace std;
void line(vector<int>& v,vector<vector<int>>& ans,vector<int>& id){
    for(int i=1;i<v.size();i++){
        ans[v[i]][v[i-1]]=1;
        id[id[v[i]]]=id[v[0]];
    }
}
bool check(int a,int b,vector<vector<int>>& p,vector<bool>& seen){
    seen[a]=seen[b]=true;
    for(int i=0;i<p.size();i++){
        if(p[a][i]!=p[b][i])return false;
    }
    return true;
}
int build_1(vector<vector<int>>& ans,vector<int>& id,vector<vector<int>>& p){
    int n=ans.size();
    vector<bool> seen(n,false);
    vector<vector<int>> lines(n);
    for(int i=0;i<n;i++){
        if(seen[i])continue;
        lines[i].push_back(i);
        for(int j=0;j<n;j++){
            if(i==j)continue;
            if(p[i][j]==1){
                if(!check(i,j,p,seen))return 0;
                lines[i].push_back(j);
            }
        }
    }
    for(int i=0;i<n;i++)line(lines[i],ans,id);
    return 1;
}
int cycle(vector<int>& v,vector<vector<int>>& ans,vector<int>& id){
    if(v.size()==2)return 0;
    if(v.size()<=1)return 1;
    //for(int x:v)cout<<x<<' ';
    line(v,ans,id);
    ans[v[0]][v[v.size()-1]]=1;
    return 1;
}
int build_2(vector<vector<int>>& ans,vector<int>& id,vector<vector<int>>& p){
    if(!build_1(ans,id,p))return 0;
    int n=ans.size();
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)if(p[i][j]==1)p[i][j]=2;
    }
    vector<bool> seen(n,false);
    vector<vector<int>> cycles(n);
    for(int i=0;i<n;i++){
        if(seen[i]||id[i]!=i)continue;
        cycles[i].push_back(i);
        for(int j=0;j<n;j++){
            if(i==j)continue;
            if(p[i][j]==2&&!seen[j]&&id[j]==j){
                if(!check(i,j,p,seen))return 0;
                cycles[i].push_back(j);
            }
        }
    }
    for(int i=0;i<n;i++)if(!cycle(cycles[i],ans,id))return 0;
    return 1;
}
int construct(vector<vector<int>> p){
	int n = p.size();
	vector<int> id(n);
	for(int i=0;i<n;i++){
        p[i][i]=0;
        id[i]=i;
	}
	vector<vector<int>> answer(n,vector<int>(n));
    int mx=0;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)mx=max(mx,p[i][j]);
    for(int i=0;i<n;i++)p[i][i]=1;
    if(mx==3)return 0;
    if(mx==1){
        if(!build_1(answer,id,p))return 0;
    }
    if(mx==2){
        if(!build_2(answer,id,p))return 0;
    }
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(answer[i][j])answer[j][i]=1;
    /*for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)cout<<answer[i][j]<<' ';
        cout<<'\n';
    }*/
	build(answer);
	return 1;
}
/*int main(){
    vector<vector<int>> v={{1,1,2,2},{1,1,2,2},{2,2,1,2},{2,2,2,1}};
    //vector<vector<int>> w={{1,1},{1,1}};
    construct (v);
}*/

Compilation message

supertrees.cpp: In function 'void line(std::vector<int>&, std::vector<std::vector<int> >&, std::vector<int>&)':
supertrees.cpp:6:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     for(int i=1;i<v.size();i++){
      |                 ~^~~~~~~~~
supertrees.cpp: In function 'bool check(int, int, std::vector<std::vector<int> >&, std::vector<bool>&)':
supertrees.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i=0;i<p.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 180 ms 23928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 180 ms 23928 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1164 KB Output is correct
13 Correct 175 ms 23924 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 78 ms 13996 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 45 ms 6220 KB Output is correct
21 Correct 191 ms 23920 KB Output is correct
22 Correct 171 ms 23900 KB Output is correct
23 Correct 182 ms 23940 KB Output is correct
24 Correct 189 ms 24012 KB Output is correct
25 Correct 72 ms 14080 KB Output is correct
26 Correct 72 ms 14072 KB Output is correct
27 Correct 199 ms 23956 KB Output is correct
28 Correct 207 ms 24012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 8 ms 1236 KB Output is correct
9 Correct 196 ms 23924 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 8 ms 1252 KB Output is correct
13 Correct 222 ms 24048 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 828 KB Output is correct
17 Correct 89 ms 14148 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 296 KB Output is correct
21 Correct 50 ms 6264 KB Output is correct
22 Correct 195 ms 23916 KB Output is correct
23 Correct 218 ms 23932 KB Output is correct
24 Correct 214 ms 23972 KB Output is correct
25 Correct 85 ms 14064 KB Output is correct
26 Correct 77 ms 14084 KB Output is correct
27 Correct 244 ms 23924 KB Output is correct
28 Correct 213 ms 23936 KB Output is correct
29 Correct 109 ms 14120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 47 ms 6260 KB Output is correct
5 Correct 186 ms 23952 KB Output is correct
6 Correct 184 ms 23988 KB Output is correct
7 Correct 181 ms 23936 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 49 ms 6264 KB Output is correct
10 Correct 191 ms 23896 KB Output is correct
11 Correct 184 ms 23936 KB Output is correct
12 Correct 185 ms 24052 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 44 ms 6264 KB Output is correct
17 Correct 206 ms 23964 KB Output is correct
18 Correct 176 ms 23960 KB Output is correct
19 Correct 181 ms 24048 KB Output is correct
20 Correct 185 ms 24012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 180 ms 23928 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1164 KB Output is correct
13 Correct 175 ms 23924 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 78 ms 13996 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 45 ms 6220 KB Output is correct
21 Correct 191 ms 23920 KB Output is correct
22 Correct 171 ms 23900 KB Output is correct
23 Correct 182 ms 23940 KB Output is correct
24 Correct 189 ms 24012 KB Output is correct
25 Correct 72 ms 14080 KB Output is correct
26 Correct 72 ms 14072 KB Output is correct
27 Correct 199 ms 23956 KB Output is correct
28 Correct 207 ms 24012 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 300 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 300 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1236 KB Output is correct
37 Correct 196 ms 23924 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 304 KB Output is correct
40 Correct 8 ms 1252 KB Output is correct
41 Correct 222 ms 24048 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 5 ms 828 KB Output is correct
45 Correct 89 ms 14148 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 296 KB Output is correct
48 Correct 1 ms 296 KB Output is correct
49 Correct 50 ms 6264 KB Output is correct
50 Correct 195 ms 23916 KB Output is correct
51 Correct 218 ms 23932 KB Output is correct
52 Correct 214 ms 23972 KB Output is correct
53 Correct 85 ms 14064 KB Output is correct
54 Correct 77 ms 14084 KB Output is correct
55 Correct 244 ms 23924 KB Output is correct
56 Correct 213 ms 23936 KB Output is correct
57 Correct 109 ms 14120 KB Output is correct
58 Correct 0 ms 300 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 3 ms 820 KB Output is correct
61 Correct 71 ms 14028 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 300 KB Output is correct
65 Correct 50 ms 6172 KB Output is correct
66 Correct 78 ms 14064 KB Output is correct
67 Correct 70 ms 14068 KB Output is correct
68 Correct 68 ms 14064 KB Output is correct
69 Correct 72 ms 14068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 180 ms 23928 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1164 KB Output is correct
13 Correct 175 ms 23924 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 78 ms 13996 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 45 ms 6220 KB Output is correct
21 Correct 191 ms 23920 KB Output is correct
22 Correct 171 ms 23900 KB Output is correct
23 Correct 182 ms 23940 KB Output is correct
24 Correct 189 ms 24012 KB Output is correct
25 Correct 72 ms 14080 KB Output is correct
26 Correct 72 ms 14072 KB Output is correct
27 Correct 199 ms 23956 KB Output is correct
28 Correct 207 ms 24012 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 300 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 300 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1236 KB Output is correct
37 Correct 196 ms 23924 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 304 KB Output is correct
40 Correct 8 ms 1252 KB Output is correct
41 Correct 222 ms 24048 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 5 ms 828 KB Output is correct
45 Correct 89 ms 14148 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 296 KB Output is correct
48 Correct 1 ms 296 KB Output is correct
49 Correct 50 ms 6264 KB Output is correct
50 Correct 195 ms 23916 KB Output is correct
51 Correct 218 ms 23932 KB Output is correct
52 Correct 214 ms 23972 KB Output is correct
53 Correct 85 ms 14064 KB Output is correct
54 Correct 77 ms 14084 KB Output is correct
55 Correct 244 ms 23924 KB Output is correct
56 Correct 213 ms 23936 KB Output is correct
57 Correct 109 ms 14120 KB Output is correct
58 Correct 1 ms 300 KB Output is correct
59 Correct 1 ms 304 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 47 ms 6260 KB Output is correct
62 Correct 186 ms 23952 KB Output is correct
63 Correct 184 ms 23988 KB Output is correct
64 Correct 181 ms 23936 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 49 ms 6264 KB Output is correct
67 Correct 191 ms 23896 KB Output is correct
68 Correct 184 ms 23936 KB Output is correct
69 Correct 185 ms 24052 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 44 ms 6264 KB Output is correct
74 Correct 206 ms 23964 KB Output is correct
75 Correct 176 ms 23960 KB Output is correct
76 Correct 181 ms 24048 KB Output is correct
77 Correct 185 ms 24012 KB Output is correct
78 Correct 0 ms 300 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 3 ms 820 KB Output is correct
81 Correct 71 ms 14028 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 300 KB Output is correct
85 Correct 50 ms 6172 KB Output is correct
86 Correct 78 ms 14064 KB Output is correct
87 Correct 70 ms 14068 KB Output is correct
88 Correct 68 ms 14064 KB Output is correct
89 Correct 72 ms 14068 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 4 ms 824 KB Output is correct
93 Correct 81 ms 13976 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 17 ms 3772 KB Output is correct
98 Correct 99 ms 14064 KB Output is correct
99 Correct 71 ms 14064 KB Output is correct
100 Correct 68 ms 14080 KB Output is correct
101 Correct 72 ms 13996 KB Output is correct
102 Correct 69 ms 14080 KB Output is correct
103 Correct 84 ms 13996 KB Output is correct
104 Correct 66 ms 14080 KB Output is correct
105 Correct 72 ms 14072 KB Output is correct