답안 #522462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522462 2022-02-05T04:33:43 Z krit3379 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
201 ms 26948 KB
#include<bits/stdc++.h>
using namespace std;
#include "supertrees.h"
#define N 1005

int p[N],pp[N];
vector<int> v;
vector<vector<int>> a,b;
bitset<N> vis,ch;

int fp(int v){return (v==p[v])?v:p[v]=fp(p[v]);}
int fpp(int v){return (v==pp[v])?v:pp[v]=fpp(pp[v]);}

bool sol(int n){
    int i,j,cy=0,head,num;
    vector<int> gr[N],u;
    ch=0;
    iota(pp,pp+n,0);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            num=a[v[i]][v[j]];
            if(num==1){
                if(fpp(i)!=fpp(j))pp[fpp(i)]=fpp(j);
            }
            else if(!cy){
                cy=num;
            }
            else if(cy!=num)return false;

        }
    }
    for(i=0;i<n;i++)gr[fpp(i)].push_back(v[i]);
    if(!cy){
        for(i=1;i<n;i++)b[v[i]][v[i-1]]=b[v[i-1]][v[i]]=1;
        return true;
    }
    else{
        for(i=0;i<n;i++){
            if(ch[fpp(i)])continue;
            head=fpp(i);
            u.push_back(v[head]);
            ch[head]=true;
            for(auto x:gr[head]){
                for(j=0;j<n;j++){
                    if(fpp(j)==head){
                        if(a[x][v[j]]!=1)return false;
                    }
                    else{
                        if(a[x][v[j]]!=cy)return false;
                    }
                }
            }
        }
        for(i=0;i<n;i++)
            for(j=1;j<gr[i].size();j++)b[gr[i][j]][gr[i][j-1]]=b[gr[i][j-1]][gr[i][j]]=1;
        if(u.size()<3)return false;
        for(i=1;i<u.size();i++)b[u[i]][u[i-1]]=b[u[i-1]][u[i]]=1;
        b[u[0]][u.back()]=b[u.back()][u[0]]=1;
        return true;
    }
}

int construct(vector<vector<int>> input) {
    a=input;
	int n=a.size(),i,j,m;
	bool flag;
	iota(p,p+n,0);
	for(i=0;i<n;i++){
        b.push_back({});
        b[i].resize(n);
        for(j=0;j<n;j++){
          	if(a[i][j]==3)return 0;
            if(a[i][j]){
                if(fp(i)==fp(j))continue;
                p[fp(i)]=fp(j);
            }
            else if(fp(i)==fp(j))return 0;
        }
	}
	for(i=0;i<n;i++){
        if(!vis[fp(i)]){
            vis[fp(i)]=true;
            for(j=0;j<n;j++)if(fp(i)==fp(j))v.push_back(j);
            m=v.size();
            flag=sol(m);
            v.clear();
            if(!flag)return 0;
        }
	}
	build(b);
	return 1;
}

Compilation message

supertrees.cpp: In function 'bool sol(int)':
supertrees.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             for(j=1;j<gr[i].size();j++)b[gr[i][j]][gr[i][j-1]]=b[gr[i][j-1]][gr[i][j]]=1;
      |                     ~^~~~~~~~~~~~~
supertrees.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for(i=1;i<u.size();i++)b[u[i]][u[i-1]]=b[u[i-1]][u[i]]=1;
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 8 ms 1356 KB Output is correct
7 Correct 174 ms 26836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 8 ms 1356 KB Output is correct
7 Correct 174 ms 26836 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 201 ms 26848 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 824 KB Output is correct
17 Correct 70 ms 13032 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 43 ms 7200 KB Output is correct
21 Correct 177 ms 26824 KB Output is correct
22 Correct 194 ms 26948 KB Output is correct
23 Correct 181 ms 26880 KB Output is correct
24 Correct 177 ms 26900 KB Output is correct
25 Correct 76 ms 16172 KB Output is correct
26 Correct 65 ms 14152 KB Output is correct
27 Correct 180 ms 26872 KB Output is correct
28 Correct 174 ms 26820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 288 KB Output is correct
8 Correct 7 ms 1440 KB Output is correct
9 Correct 169 ms 26820 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1356 KB Output is correct
13 Correct 171 ms 26812 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 3 ms 844 KB Output is correct
17 Correct 70 ms 12952 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 292 KB Output is correct
21 Correct 43 ms 7236 KB Output is correct
22 Correct 177 ms 26320 KB Output is correct
23 Correct 176 ms 26180 KB Output is correct
24 Correct 182 ms 26216 KB Output is correct
25 Correct 72 ms 16324 KB Output is correct
26 Correct 69 ms 12556 KB Output is correct
27 Correct 180 ms 26372 KB Output is correct
28 Correct 178 ms 26164 KB Output is correct
29 Correct 80 ms 16260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 43 ms 7252 KB Output is correct
5 Correct 172 ms 26896 KB Output is correct
6 Correct 177 ms 26896 KB Output is correct
7 Correct 185 ms 26808 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 43 ms 7276 KB Output is correct
10 Correct 168 ms 26224 KB Output is correct
11 Correct 173 ms 26284 KB Output is correct
12 Correct 185 ms 26188 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 46 ms 6980 KB Output is correct
17 Correct 174 ms 26284 KB Output is correct
18 Correct 170 ms 26264 KB Output is correct
19 Correct 168 ms 26264 KB Output is correct
20 Correct 166 ms 26200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 8 ms 1356 KB Output is correct
7 Correct 174 ms 26836 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 201 ms 26848 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 824 KB Output is correct
17 Correct 70 ms 13032 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 43 ms 7200 KB Output is correct
21 Correct 177 ms 26824 KB Output is correct
22 Correct 194 ms 26948 KB Output is correct
23 Correct 181 ms 26880 KB Output is correct
24 Correct 177 ms 26900 KB Output is correct
25 Correct 76 ms 16172 KB Output is correct
26 Correct 65 ms 14152 KB Output is correct
27 Correct 180 ms 26872 KB Output is correct
28 Correct 174 ms 26820 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 296 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 292 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 288 KB Output is correct
36 Correct 7 ms 1440 KB Output is correct
37 Correct 169 ms 26820 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 8 ms 1356 KB Output is correct
41 Correct 171 ms 26812 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 3 ms 844 KB Output is correct
45 Correct 70 ms 12952 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 ms 292 KB Output is correct
49 Correct 43 ms 7236 KB Output is correct
50 Correct 177 ms 26320 KB Output is correct
51 Correct 176 ms 26180 KB Output is correct
52 Correct 182 ms 26216 KB Output is correct
53 Correct 72 ms 16324 KB Output is correct
54 Correct 69 ms 12556 KB Output is correct
55 Correct 180 ms 26372 KB Output is correct
56 Correct 178 ms 26164 KB Output is correct
57 Correct 80 ms 16260 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 0 ms 296 KB Output is correct
60 Correct 3 ms 820 KB Output is correct
61 Correct 79 ms 12412 KB Output is correct
62 Correct 0 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 46 ms 6976 KB Output is correct
66 Correct 69 ms 12432 KB Output is correct
67 Correct 65 ms 12464 KB Output is correct
68 Correct 67 ms 13896 KB Output is correct
69 Correct 67 ms 16340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 8 ms 1356 KB Output is correct
7 Correct 174 ms 26836 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 201 ms 26848 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 824 KB Output is correct
17 Correct 70 ms 13032 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 43 ms 7200 KB Output is correct
21 Correct 177 ms 26824 KB Output is correct
22 Correct 194 ms 26948 KB Output is correct
23 Correct 181 ms 26880 KB Output is correct
24 Correct 177 ms 26900 KB Output is correct
25 Correct 76 ms 16172 KB Output is correct
26 Correct 65 ms 14152 KB Output is correct
27 Correct 180 ms 26872 KB Output is correct
28 Correct 174 ms 26820 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 296 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 292 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 288 KB Output is correct
36 Correct 7 ms 1440 KB Output is correct
37 Correct 169 ms 26820 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 8 ms 1356 KB Output is correct
41 Correct 171 ms 26812 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 3 ms 844 KB Output is correct
45 Correct 70 ms 12952 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 ms 292 KB Output is correct
49 Correct 43 ms 7236 KB Output is correct
50 Correct 177 ms 26320 KB Output is correct
51 Correct 176 ms 26180 KB Output is correct
52 Correct 182 ms 26216 KB Output is correct
53 Correct 72 ms 16324 KB Output is correct
54 Correct 69 ms 12556 KB Output is correct
55 Correct 180 ms 26372 KB Output is correct
56 Correct 178 ms 26164 KB Output is correct
57 Correct 80 ms 16260 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 1 ms 292 KB Output is correct
61 Correct 43 ms 7252 KB Output is correct
62 Correct 172 ms 26896 KB Output is correct
63 Correct 177 ms 26896 KB Output is correct
64 Correct 185 ms 26808 KB Output is correct
65 Correct 1 ms 296 KB Output is correct
66 Correct 43 ms 7276 KB Output is correct
67 Correct 168 ms 26224 KB Output is correct
68 Correct 173 ms 26284 KB Output is correct
69 Correct 185 ms 26188 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 0 ms 204 KB Output is correct
73 Correct 46 ms 6980 KB Output is correct
74 Correct 174 ms 26284 KB Output is correct
75 Correct 170 ms 26264 KB Output is correct
76 Correct 168 ms 26264 KB Output is correct
77 Correct 166 ms 26200 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 0 ms 296 KB Output is correct
80 Correct 3 ms 820 KB Output is correct
81 Correct 79 ms 12412 KB Output is correct
82 Correct 0 ms 204 KB Output is correct
83 Correct 1 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 46 ms 6976 KB Output is correct
86 Correct 69 ms 12432 KB Output is correct
87 Correct 65 ms 12464 KB Output is correct
88 Correct 67 ms 13896 KB Output is correct
89 Correct 67 ms 16340 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 3 ms 844 KB Output is correct
93 Correct 71 ms 12288 KB Output is correct
94 Correct 0 ms 296 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 0 ms 300 KB Output is correct
97 Correct 19 ms 3744 KB Output is correct
98 Correct 65 ms 12564 KB Output is correct
99 Correct 65 ms 12948 KB Output is correct
100 Correct 65 ms 12688 KB Output is correct
101 Correct 69 ms 13672 KB Output is correct
102 Correct 63 ms 12300 KB Output is correct
103 Correct 71 ms 12392 KB Output is correct
104 Correct 63 ms 12316 KB Output is correct
105 Correct 69 ms 12356 KB Output is correct