답안 #329526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
329526 2020-11-21T12:26:08 Z blue 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
273 ms 28140 KB
#include "supertrees.h"
#include <vector>
using namespace std;

int construct(vector< vector<int> > p)
{
    int n = p.size();

    vector<int> chain(n, -1), ring(n, -1);
    for(int i = 0; i < n; i++) chain[i] = ring[i] = i;

    for(int j = 0; j < n; j++)
    {
        for(int i = 0; i < j; i++)
        {
            if(ring[i] == i)
            {
                if(p[i][j] >= 1)
                {
                    ring[j] = ring[i];
                    break;
                }
            }
            else
            {
                if(p[i][j] >= 1 && ring[i] != ring[j]) return 0;
                if(p[i][j] == 0 && ring[i] == ring[j]) return 0;
            }
        }
        for(int i = 0; i < j; i++)
        {
            if(chain[j] == j)
            {
                if(p[i][j] == 1)
                {
                    chain[j] = chain[i];
                    break;
                }
            }
            else
            {
                if(p[i][j] == 1 && chain[i] != chain[j]) return 0;
                if(p[i][j] != 1 && chain[i] == chain[j]) return 0;
            }
        }
    }

    for(int i = 0; i < n; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            if(p[i][j] == 0)
            {
                if(chain[i] == chain[j]) return 0;
                if(ring[i] == ring[j]) return 0;
            }
            else if(p[i][j] == 1)
            {
                if(chain[i] != chain[j]) return 0;
                if(ring[i] != ring[j]) return 0;
            }
            else if(p[i][j] == 2)
            {
                if(chain[i] == chain[j]) return 0;
                if(ring[i] != ring[j]) return 0;
            }
            else if(p[i][j] == 3)
            {
                return 0;
            }

            if(ring[i] == ring[j])
            {
                if(p[i][j] == 0) return 0;
            }
            else
            {
                if(p[i][j] != 0) return 0;
            }

            if(chain[i] == chain[j])
            {
                if(p[i][j] != 1) return 0;
            }
            else
            {
                if(p[i][j] == 1) return 0;
            }
        }
    }

    vector< vector<int> > neighbors(n);
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++)
    {
        if(i == j) continue;
        if(p[i][j] >= 1)
        {
            neighbors[i].push_back(j);
        }
    }

    for(int i = 0; i < n; i++)
    {
        if(neighbors[i].size() == 1 && p[i][neighbors[i][0]] != 1) return 0;
    }

    vector< vector<int> > b (n, vector<int>(n, 0));

    vector<int> oncycle(n, 1);

    for(int i = 0; i < n; i++)
    {
        for(int j = i-1; j >= 0; j--)
            if(p[i][j] == 1)
            {
                oncycle[i] = 0;
                b[i][j] = b[j][i] = 1;
                break;
            }
    }
    int pre;
    for(int i = 0; i < n; i++)
    {
        if(!oncycle[i]) continue;
        pre = i;
        oncycle[i] = 0;
        for(int j = i+1; j < n; j++)
        {
            if(!oncycle[j]) continue;
            if(p[pre][j] == 2)
            {
                b[pre][j] = b[j][pre] = 1;
                pre = j;
                oncycle[j] = 0;
            }
        }
        if(pre != i) b[pre][i] = b[i][pre] = 1;
    }
    build(b);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 11 ms 1516 KB Output is correct
7 Correct 255 ms 28140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 11 ms 1516 KB Output is correct
7 Correct 255 ms 28140 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 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 24044 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 123 ms 10220 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 63 ms 6380 KB Output is correct
21 Correct 255 ms 24600 KB Output is correct
22 Correct 258 ms 24044 KB Output is correct
23 Correct 260 ms 26220 KB Output is correct
24 Correct 264 ms 24172 KB Output is correct
25 Correct 123 ms 10220 KB Output is correct
26 Correct 116 ms 10220 KB Output is correct
27 Correct 273 ms 27116 KB Output is correct
28 Correct 255 ms 24044 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 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 11 ms 1260 KB Output is correct
9 Correct 253 ms 24064 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 11 ms 1536 KB Output is correct
13 Correct 262 ms 28140 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 123 ms 10220 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 0 ms 364 KB Output is correct
21 Correct 63 ms 6380 KB Output is correct
22 Correct 255 ms 24684 KB Output is correct
23 Correct 257 ms 24300 KB Output is correct
24 Correct 267 ms 27116 KB Output is correct
25 Correct 119 ms 10220 KB Output is correct
26 Correct 118 ms 10144 KB Output is correct
27 Correct 255 ms 24044 KB Output is correct
28 Correct 264 ms 26092 KB Output is correct
29 Correct 125 ms 10220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 64 ms 6316 KB Output is correct
5 Correct 254 ms 24684 KB Output is correct
6 Correct 264 ms 24044 KB Output is correct
7 Correct 258 ms 26092 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 65 ms 6380 KB Output is correct
10 Correct 266 ms 24684 KB Output is correct
11 Correct 253 ms 24132 KB Output is correct
12 Correct 268 ms 27116 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 62 ms 6380 KB Output is correct
17 Correct 258 ms 24556 KB Output is correct
18 Correct 253 ms 24556 KB Output is correct
19 Correct 249 ms 24300 KB Output is correct
20 Correct 262 ms 24200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 11 ms 1516 KB Output is correct
7 Correct 255 ms 28140 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 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 24044 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 123 ms 10220 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 63 ms 6380 KB Output is correct
21 Correct 255 ms 24600 KB Output is correct
22 Correct 258 ms 24044 KB Output is correct
23 Correct 260 ms 26220 KB Output is correct
24 Correct 264 ms 24172 KB Output is correct
25 Correct 123 ms 10220 KB Output is correct
26 Correct 116 ms 10220 KB Output is correct
27 Correct 273 ms 27116 KB Output is correct
28 Correct 255 ms 24044 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 0 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 0 ms 364 KB Output is correct
34 Correct 0 ms 364 KB Output is correct
35 Correct 0 ms 364 KB Output is correct
36 Correct 11 ms 1260 KB Output is correct
37 Correct 253 ms 24064 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 0 ms 364 KB Output is correct
40 Correct 11 ms 1536 KB Output is correct
41 Correct 262 ms 28140 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 123 ms 10220 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 0 ms 364 KB Output is correct
48 Correct 0 ms 364 KB Output is correct
49 Correct 63 ms 6380 KB Output is correct
50 Correct 255 ms 24684 KB Output is correct
51 Correct 257 ms 24300 KB Output is correct
52 Correct 267 ms 27116 KB Output is correct
53 Correct 119 ms 10220 KB Output is correct
54 Correct 118 ms 10144 KB Output is correct
55 Correct 255 ms 24044 KB Output is correct
56 Correct 264 ms 26092 KB Output is correct
57 Correct 125 ms 10220 KB Output is correct
58 Correct 0 ms 364 KB Output is correct
59 Correct 0 ms 364 KB Output is correct
60 Correct 6 ms 748 KB Output is correct
61 Correct 122 ms 10220 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 63 ms 6380 KB Output is correct
66 Correct 123 ms 10220 KB Output is correct
67 Correct 114 ms 10220 KB Output is correct
68 Correct 118 ms 10324 KB Output is correct
69 Correct 121 ms 10220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 11 ms 1516 KB Output is correct
7 Correct 255 ms 28140 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 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 24044 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 123 ms 10220 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 63 ms 6380 KB Output is correct
21 Correct 255 ms 24600 KB Output is correct
22 Correct 258 ms 24044 KB Output is correct
23 Correct 260 ms 26220 KB Output is correct
24 Correct 264 ms 24172 KB Output is correct
25 Correct 123 ms 10220 KB Output is correct
26 Correct 116 ms 10220 KB Output is correct
27 Correct 273 ms 27116 KB Output is correct
28 Correct 255 ms 24044 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 0 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 0 ms 364 KB Output is correct
34 Correct 0 ms 364 KB Output is correct
35 Correct 0 ms 364 KB Output is correct
36 Correct 11 ms 1260 KB Output is correct
37 Correct 253 ms 24064 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 0 ms 364 KB Output is correct
40 Correct 11 ms 1536 KB Output is correct
41 Correct 262 ms 28140 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 123 ms 10220 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 0 ms 364 KB Output is correct
48 Correct 0 ms 364 KB Output is correct
49 Correct 63 ms 6380 KB Output is correct
50 Correct 255 ms 24684 KB Output is correct
51 Correct 257 ms 24300 KB Output is correct
52 Correct 267 ms 27116 KB Output is correct
53 Correct 119 ms 10220 KB Output is correct
54 Correct 118 ms 10144 KB Output is correct
55 Correct 255 ms 24044 KB Output is correct
56 Correct 264 ms 26092 KB Output is correct
57 Correct 125 ms 10220 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 0 ms 364 KB Output is correct
60 Correct 0 ms 364 KB Output is correct
61 Correct 64 ms 6316 KB Output is correct
62 Correct 254 ms 24684 KB Output is correct
63 Correct 264 ms 24044 KB Output is correct
64 Correct 258 ms 26092 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 65 ms 6380 KB Output is correct
67 Correct 266 ms 24684 KB Output is correct
68 Correct 253 ms 24132 KB Output is correct
69 Correct 268 ms 27116 KB Output is correct
70 Correct 0 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 62 ms 6380 KB Output is correct
74 Correct 258 ms 24556 KB Output is correct
75 Correct 253 ms 24556 KB Output is correct
76 Correct 249 ms 24300 KB Output is correct
77 Correct 262 ms 24200 KB Output is correct
78 Correct 0 ms 364 KB Output is correct
79 Correct 0 ms 364 KB Output is correct
80 Correct 6 ms 748 KB Output is correct
81 Correct 122 ms 10220 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 63 ms 6380 KB Output is correct
86 Correct 123 ms 10220 KB Output is correct
87 Correct 114 ms 10220 KB Output is correct
88 Correct 118 ms 10324 KB Output is correct
89 Correct 121 ms 10220 KB Output is correct
90 Correct 0 ms 364 KB Output is correct
91 Correct 0 ms 364 KB Output is correct
92 Correct 6 ms 748 KB Output is correct
93 Correct 119 ms 10220 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 0 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 29 ms 2796 KB Output is correct
98 Correct 121 ms 10220 KB Output is correct
99 Correct 123 ms 10220 KB Output is correct
100 Correct 120 ms 10220 KB Output is correct
101 Correct 119 ms 10220 KB Output is correct
102 Correct 123 ms 10220 KB Output is correct
103 Correct 121 ms 10220 KB Output is correct
104 Correct 122 ms 10220 KB Output is correct
105 Correct 121 ms 10348 KB Output is correct