답안 #386204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386204 2021-04-06T04:46:35 Z Pichon5 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
301 ms 24300 KB
#include "supertrees.h"
#include<bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
//"\n"
using namespace std;
const int tam=1001;
int P0[tam];
int P1[tam];
int P2[tam];
void init(){
    for(int i=0;i<tam;i++){
        P0[i]=P1[i]=P2[i]=i;
    }
}
int find0(int a){
    if(a==P0[a])return a;
    return P0[a]=find0(P0[a]);
}
int find1(int a){
    if(a==P1[a])return a;
    return P1[a]=find1(P1[a]);
}
int find2(int a){
    if(a==P2[a])return a;
    return P2[a]=find2(P2[a]);
}
void union0(int a,int b){
    a=find0(a);b=find0(b);
    P0[a]=b;
}
void union1(int a,int b){
    a=find1(a);b=find1(b);
    P1[a]=b;
}
void union2(int a,int b){
    a=find2(a);b=find2(b);
    P2[a]=b;
}

int construct(vector<vi> p){
    init();
	int n = p.size();
	vector<vector<int> > res(n,vector<int>(n,0));
	for(int i=0;i<n;i++){
        for(int l=0;l<n;l++){
            if(p[i][l]==3)return 0;
            if(p[i][l]!=0){
                union0(i,l);
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int l=i+1;l<n;l++){
            if(p[i][l]==0 && find0(i)==find0(l)){
                return 0;
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int l=i+1;l<n;l++){
            if(p[i][l]==1){
                union1(i,l);
            }
        }
    }
    for(int i=0;i<n;i++){
        int v=find1(i);
        if(i!=v)res[i][v]=res[v][i]=1;
        for(int l=i+1;l<n;l++){
            if(p[i][l]==2 && find1(i)==find1(l)){
                return 0;
            }
            if(p[i][l]==2){
                union2(find1(i),find1(l));
            }
        }
    }
    vector<vi>G(n+1);
    for(int i=0;i<n;i++){
        int e=find2(i);
        G[e].pb(i);
    }
    for(int i=0;i<n;i++){
        if(G[i].size()<=1)continue;
        if(G[i].size()==2)return 0;
        int u,v;
        for(int l=0;l<G[i].size()-1;l++){
            u=G[i][l],v=G[i][l+1];
            res[u][v]=res[v][u]=1;
        }
        u=G[i][0],v=G[i][G[i].size()-1];
        res[u][v]=res[v][u]=1;
    }
    build(res);
	return 1;


}
/*
4
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0

4
0 2 2 2
2 0 2 2
2 2 0 2
2 2 2 0
*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:94:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         for(int l=0;l<G[i].size()-1;l++){
      |                     ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 13 ms 1260 KB Output is correct
7 Correct 250 ms 24172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 13 ms 1260 KB Output is correct
7 Correct 250 ms 24172 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 257 ms 23660 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 900 KB Output is correct
17 Correct 115 ms 14188 KB Output is correct
18 Correct 1 ms 368 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 64 ms 6380 KB Output is correct
21 Correct 261 ms 24300 KB Output is correct
22 Correct 250 ms 24172 KB Output is correct
23 Correct 281 ms 24300 KB Output is correct
24 Correct 254 ms 24172 KB Output is correct
25 Correct 118 ms 14188 KB Output is correct
26 Correct 102 ms 14188 KB Output is correct
27 Correct 287 ms 24148 KB Output is correct
28 Correct 249 ms 24172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 13 ms 1260 KB Output is correct
9 Correct 251 ms 24172 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 249 ms 24172 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 876 KB Output is correct
17 Correct 114 ms 14188 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 64 ms 6380 KB Output is correct
22 Correct 255 ms 24172 KB Output is correct
23 Correct 301 ms 24044 KB Output is correct
24 Correct 275 ms 24172 KB Output is correct
25 Correct 104 ms 14188 KB Output is correct
26 Correct 103 ms 14188 KB Output is correct
27 Correct 252 ms 23660 KB Output is correct
28 Correct 268 ms 24044 KB Output is correct
29 Correct 102 ms 14188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 64 ms 6380 KB Output is correct
5 Correct 259 ms 24300 KB Output is correct
6 Correct 257 ms 24096 KB Output is correct
7 Correct 266 ms 24172 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 66 ms 6380 KB Output is correct
10 Correct 259 ms 24172 KB Output is correct
11 Correct 269 ms 24044 KB Output is correct
12 Correct 267 ms 24044 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 63 ms 6380 KB Output is correct
17 Correct 253 ms 24044 KB Output is correct
18 Correct 265 ms 24044 KB Output is correct
19 Correct 259 ms 24044 KB Output is correct
20 Correct 247 ms 24172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 13 ms 1260 KB Output is correct
7 Correct 250 ms 24172 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 257 ms 23660 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 900 KB Output is correct
17 Correct 115 ms 14188 KB Output is correct
18 Correct 1 ms 368 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 64 ms 6380 KB Output is correct
21 Correct 261 ms 24300 KB Output is correct
22 Correct 250 ms 24172 KB Output is correct
23 Correct 281 ms 24300 KB Output is correct
24 Correct 254 ms 24172 KB Output is correct
25 Correct 118 ms 14188 KB Output is correct
26 Correct 102 ms 14188 KB Output is correct
27 Correct 287 ms 24148 KB Output is correct
28 Correct 249 ms 24172 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 13 ms 1260 KB Output is correct
37 Correct 251 ms 24172 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11 ms 1260 KB Output is correct
41 Correct 249 ms 24172 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 876 KB Output is correct
45 Correct 114 ms 14188 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 64 ms 6380 KB Output is correct
50 Correct 255 ms 24172 KB Output is correct
51 Correct 301 ms 24044 KB Output is correct
52 Correct 275 ms 24172 KB Output is correct
53 Correct 104 ms 14188 KB Output is correct
54 Correct 103 ms 14188 KB Output is correct
55 Correct 252 ms 23660 KB Output is correct
56 Correct 268 ms 24044 KB Output is correct
57 Correct 102 ms 14188 KB Output is correct
58 Correct 2 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 6 ms 876 KB Output is correct
61 Correct 113 ms 14188 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 81 ms 6380 KB Output is correct
66 Correct 105 ms 14164 KB Output is correct
67 Correct 105 ms 14188 KB Output is correct
68 Correct 101 ms 14188 KB Output is correct
69 Correct 136 ms 14188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 13 ms 1260 KB Output is correct
7 Correct 250 ms 24172 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 257 ms 23660 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 900 KB Output is correct
17 Correct 115 ms 14188 KB Output is correct
18 Correct 1 ms 368 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 64 ms 6380 KB Output is correct
21 Correct 261 ms 24300 KB Output is correct
22 Correct 250 ms 24172 KB Output is correct
23 Correct 281 ms 24300 KB Output is correct
24 Correct 254 ms 24172 KB Output is correct
25 Correct 118 ms 14188 KB Output is correct
26 Correct 102 ms 14188 KB Output is correct
27 Correct 287 ms 24148 KB Output is correct
28 Correct 249 ms 24172 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 13 ms 1260 KB Output is correct
37 Correct 251 ms 24172 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11 ms 1260 KB Output is correct
41 Correct 249 ms 24172 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 876 KB Output is correct
45 Correct 114 ms 14188 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 64 ms 6380 KB Output is correct
50 Correct 255 ms 24172 KB Output is correct
51 Correct 301 ms 24044 KB Output is correct
52 Correct 275 ms 24172 KB Output is correct
53 Correct 104 ms 14188 KB Output is correct
54 Correct 103 ms 14188 KB Output is correct
55 Correct 252 ms 23660 KB Output is correct
56 Correct 268 ms 24044 KB Output is correct
57 Correct 102 ms 14188 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 64 ms 6380 KB Output is correct
62 Correct 259 ms 24300 KB Output is correct
63 Correct 257 ms 24096 KB Output is correct
64 Correct 266 ms 24172 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 66 ms 6380 KB Output is correct
67 Correct 259 ms 24172 KB Output is correct
68 Correct 269 ms 24044 KB Output is correct
69 Correct 267 ms 24044 KB Output is correct
70 Correct 1 ms 512 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 63 ms 6380 KB Output is correct
74 Correct 253 ms 24044 KB Output is correct
75 Correct 265 ms 24044 KB Output is correct
76 Correct 259 ms 24044 KB Output is correct
77 Correct 247 ms 24172 KB Output is correct
78 Correct 2 ms 364 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 6 ms 876 KB Output is correct
81 Correct 113 ms 14188 KB Output is correct
82 Correct 1 ms 364 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 81 ms 6380 KB Output is correct
86 Correct 105 ms 14164 KB Output is correct
87 Correct 105 ms 14188 KB Output is correct
88 Correct 101 ms 14188 KB Output is correct
89 Correct 136 ms 14188 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 5 ms 876 KB Output is correct
93 Correct 96 ms 14188 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 26 ms 3820 KB Output is correct
98 Correct 102 ms 14188 KB Output is correct
99 Correct 100 ms 14188 KB Output is correct
100 Correct 100 ms 14188 KB Output is correct
101 Correct 113 ms 14188 KB Output is correct
102 Correct 93 ms 14188 KB Output is correct
103 Correct 89 ms 14188 KB Output is correct
104 Correct 95 ms 14188 KB Output is correct
105 Correct 121 ms 14188 KB Output is correct