답안 #425523

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
425523 2021-06-13T06:23:57 Z p_square 슈퍼트리 잇기 (IOI20_supertrees) C++14
96 / 100
325 ms 24184 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

int fd_root(int a, int par[])
{
    if(par[a] == a)
        return a;

    par[a] = par[par[a]];
    return fd_root(par[a], par);
}

void merge(int a, int b, int par[])
{
    a = fd_root(a, par);
    b = fd_root(b, par);
    //cout<<a<<b<<endl;
    par[a] = b;
}

int construct(vector < vector <int> > p)
{
    int n = p.size();
    vector < vector <int> > edge;
    vector <int> empty;
    for(int i = 0; i<n; i++)
    {
        edge.push_back(empty);
        for(int j = 0; j<n; j++)
        {
            edge[i].push_back(0);
        }
    }

    int clpar[n], farpar[n];
    for(int i = 0; i<n; i++)
    {
        clpar[i] = i;
        farpar[i] = i;
    }

    for(int i = 0; i<n; i++)
    {
        for(int j = 0; j<n; j++)
        {
            if(p[i][j] != 0)
                merge(i, j, farpar);
            if(p[i][j] == 1)
                merge(i, j, clpar);
        }
    }

    bool possible = true;
    for(int i = 0; i<n; i++)
    {
        for(int j = 0; j<n; j++)
        {
            if(fd_root(i, clpar) == fd_root(j, clpar) && p[i][j] != 1)
                possible = false;

            if(fd_root(i, farpar) == fd_root(j, farpar) && p[i][j] == 0)
                possible = false;
        }
    }

    if(!possible)
        return 0;

    for(int i = 0; i<n; i++)
    {
        if(clpar[i] != i)
        {
            edge[i][clpar[i]] = 1;
            edge[clpar[i]][i] = 1;
        }
    }

    vector <int> cycle[n];

    for(int i = 0; i<n; i++)
    {
    	if(clpar[i] == i)
    	{
    		cycle[farpar[i]].push_back(i);
    	}
    }

    int u, v, z;
    for(int i = 0; i<n; i++)
    {
    	if(farpar[i] == i)
    	{
    		if(cycle[i].size() == 2)
    			possible = false;

    		if(cycle[i].size() > 2)
    		{
    			z = cycle[i].size();
    			for(int j = 0; j<z-1; j++)
    			{
    				u = cycle[i][j];
    				v = cycle[i][j+1];
    				edge[u][v] = 1;
    				edge[v][u] = 1;
    			}
    			u = cycle[i][0];
    			v = cycle[i][z-1];
    			edge[u][v] = 1;
    			edge[v][u] = 1;
    		}
    	}
    }

    if(!possible)
    	return 0;

    build(edge);
    return 1;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 268 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1228 KB Output is correct
7 Correct 265 ms 24028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 268 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1228 KB Output is correct
7 Correct 265 ms 24028 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1228 KB Output is correct
13 Correct 242 ms 24044 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 7 ms 840 KB Output is correct
17 Correct 132 ms 14068 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 62 ms 6248 KB Output is correct
21 Correct 245 ms 24052 KB Output is correct
22 Correct 239 ms 24132 KB Output is correct
23 Correct 255 ms 24132 KB Output is correct
24 Correct 249 ms 24060 KB Output is correct
25 Correct 112 ms 14188 KB Output is correct
26 Correct 109 ms 14200 KB Output is correct
27 Correct 256 ms 24056 KB Output is correct
28 Correct 247 ms 24136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 11 ms 1264 KB Output is correct
9 Correct 278 ms 24052 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1228 KB Output is correct
13 Correct 262 ms 24116 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 844 KB Output is correct
17 Correct 127 ms 14188 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 78 ms 6212 KB Output is correct
22 Correct 246 ms 24104 KB Output is correct
23 Correct 325 ms 24068 KB Output is correct
24 Correct 260 ms 24056 KB Output is correct
25 Correct 122 ms 14196 KB Output is correct
26 Correct 110 ms 14188 KB Output is correct
27 Correct 245 ms 24124 KB Output is correct
28 Correct 254 ms 24132 KB Output is correct
29 Correct 107 ms 14188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 76 ms 6228 KB Output is correct
5 Correct 248 ms 24052 KB Output is correct
6 Correct 244 ms 24056 KB Output is correct
7 Correct 295 ms 24040 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 64 ms 6380 KB Output is correct
10 Correct 244 ms 24156 KB Output is correct
11 Correct 235 ms 24048 KB Output is correct
12 Correct 258 ms 24140 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 62 ms 6252 KB Output is correct
17 Correct 246 ms 24056 KB Output is correct
18 Correct 247 ms 24128 KB Output is correct
19 Correct 285 ms 24184 KB Output is correct
20 Correct 247 ms 24132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 268 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1228 KB Output is correct
7 Correct 265 ms 24028 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1228 KB Output is correct
13 Correct 242 ms 24044 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 7 ms 840 KB Output is correct
17 Correct 132 ms 14068 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 62 ms 6248 KB Output is correct
21 Correct 245 ms 24052 KB Output is correct
22 Correct 239 ms 24132 KB Output is correct
23 Correct 255 ms 24132 KB Output is correct
24 Correct 249 ms 24060 KB Output is correct
25 Correct 112 ms 14188 KB Output is correct
26 Correct 109 ms 14200 KB Output is correct
27 Correct 256 ms 24056 KB Output is correct
28 Correct 247 ms 24136 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 300 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 288 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 11 ms 1264 KB Output is correct
37 Correct 278 ms 24052 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1228 KB Output is correct
41 Correct 262 ms 24116 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 6 ms 844 KB Output is correct
45 Correct 127 ms 14188 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 78 ms 6212 KB Output is correct
50 Correct 246 ms 24104 KB Output is correct
51 Correct 325 ms 24068 KB Output is correct
52 Correct 260 ms 24056 KB Output is correct
53 Correct 122 ms 14196 KB Output is correct
54 Correct 110 ms 14188 KB Output is correct
55 Correct 245 ms 24124 KB Output is correct
56 Correct 254 ms 24132 KB Output is correct
57 Correct 107 ms 14188 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 6 ms 788 KB Output is correct
61 Correct 159 ms 14192 KB Output is correct
62 Correct 1 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 62 ms 6280 KB Output is correct
66 Correct 109 ms 14192 KB Output is correct
67 Correct 121 ms 14148 KB Output is correct
68 Correct 109 ms 14072 KB Output is correct
69 Correct 109 ms 14276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 268 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1228 KB Output is correct
7 Correct 265 ms 24028 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1228 KB Output is correct
13 Correct 242 ms 24044 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 7 ms 840 KB Output is correct
17 Correct 132 ms 14068 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 62 ms 6248 KB Output is correct
21 Correct 245 ms 24052 KB Output is correct
22 Correct 239 ms 24132 KB Output is correct
23 Correct 255 ms 24132 KB Output is correct
24 Correct 249 ms 24060 KB Output is correct
25 Correct 112 ms 14188 KB Output is correct
26 Correct 109 ms 14200 KB Output is correct
27 Correct 256 ms 24056 KB Output is correct
28 Correct 247 ms 24136 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 300 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 288 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 11 ms 1264 KB Output is correct
37 Correct 278 ms 24052 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1228 KB Output is correct
41 Correct 262 ms 24116 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 6 ms 844 KB Output is correct
45 Correct 127 ms 14188 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 78 ms 6212 KB Output is correct
50 Correct 246 ms 24104 KB Output is correct
51 Correct 325 ms 24068 KB Output is correct
52 Correct 260 ms 24056 KB Output is correct
53 Correct 122 ms 14196 KB Output is correct
54 Correct 110 ms 14188 KB Output is correct
55 Correct 245 ms 24124 KB Output is correct
56 Correct 254 ms 24132 KB Output is correct
57 Correct 107 ms 14188 KB Output is correct
58 Correct 1 ms 288 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 292 KB Output is correct
61 Correct 76 ms 6228 KB Output is correct
62 Correct 248 ms 24052 KB Output is correct
63 Correct 244 ms 24056 KB Output is correct
64 Correct 295 ms 24040 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 64 ms 6380 KB Output is correct
67 Correct 244 ms 24156 KB Output is correct
68 Correct 235 ms 24048 KB Output is correct
69 Correct 258 ms 24140 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 62 ms 6252 KB Output is correct
74 Correct 246 ms 24056 KB Output is correct
75 Correct 247 ms 24128 KB Output is correct
76 Correct 285 ms 24184 KB Output is correct
77 Correct 247 ms 24132 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 6 ms 788 KB Output is correct
81 Correct 159 ms 14192 KB Output is correct
82 Correct 1 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 62 ms 6280 KB Output is correct
86 Correct 109 ms 14192 KB Output is correct
87 Correct 121 ms 14148 KB Output is correct
88 Correct 109 ms 14072 KB Output is correct
89 Correct 109 ms 14276 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 6 ms 844 KB Output is correct
93 Correct 126 ms 14112 KB Output is correct
94 Incorrect 1 ms 204 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -