답안 #403869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403869 2021-05-13T14:27:12 Z SamAnd 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
288 ms 27500 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef long long ll;
const int N = 1003;

int n;
vector<vector<int> > p;

bool c[N];

vector<int> v;
void dfs(int x)
{
    if (c[x])
        return;
    c[x] = true;
    v.push_back(x);
    for (int h = 0; h < n; ++h)
    {
        if (p[x][h])
        {
            dfs(h);
        }
    }
}

vector<vector<int> > vv;
bool cc[N];
vector<int> vs;
void dfss(int x)
{
    if (cc[x])
        return;
    cc[x] = true;
    vs.push_back(x);
    for (int h = 0; h < n; ++h)
    {
        if (p[x][h] == 1)
        {
            dfss(h);
        }
    }
}

int construct(vector<vector<int> > p)
{
    ::p = p;
	n = p.size();
    vector<vector<int> > ans;
	for (int i = 0; i < n; i++)
    {
		vector<int> row;
		row.resize(n);
		ans.push_back(row);
	}

	for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (p[i][j] == 3)
                return 0;
        }
    }

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            ans[i][j] = 0;
        }
    }

    for (int i = 0; i < n; ++i)
    {
        if (!c[i])
        {
            v.clear();
            dfs(i);
            for (int i = 0; i < sz(v); ++i)
            {
                for (int j = 0; j < sz(v); ++j)
                {
                    if (!p[v[i]][v[j]])
                        return 0;
                }
            }

            vv.clear();
            for (int i = 0; i < sz(v); ++i)
            {
                if (!cc[v[i]])
                {
                    vs.clear();
                    dfss(v[i]);
                    for (int i = 0; i < sz(vs); ++i)
                    {
                        for (int j = 0; j < sz(vs); ++j)
                        {
                            if (p[vs[i]][vs[j]] != 1)
                                return 0;
                        }
                    }
                    vv.push_back(vs);
                }
            }

            if (sz(vv) == 2)
                return 0;

            for (int i = 0; i < sz(vv); ++i)
            {
                for (int j = 0; j < sz(vv[i]) - 1; ++j)
                {
                    ans[vv[i][j]][vv[i][j + 1]] = 1;
                }
            }
            if (sz(vv) != 1)
                for (int i = 0; i < sz(vv); ++i)
                    ans[vv[i][0]][vv[(i + 1) % sz(vv)][0]] = 1;
        }
    }

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (ans[i][j] == 1)
                ans[j][i] = 1;
        }
    }

    build(ans);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 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 1356 KB Output is correct
7 Correct 250 ms 25992 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 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 1356 KB Output is correct
7 Correct 250 ms 25992 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 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1356 KB Output is correct
13 Correct 246 ms 25968 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 844 KB Output is correct
17 Correct 119 ms 16268 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 61 ms 6660 KB Output is correct
21 Correct 241 ms 25904 KB Output is correct
22 Correct 238 ms 25924 KB Output is correct
23 Correct 255 ms 26100 KB Output is correct
24 Correct 232 ms 26004 KB Output is correct
25 Correct 105 ms 16068 KB Output is correct
26 Correct 97 ms 16144 KB Output is correct
27 Correct 256 ms 25924 KB Output is correct
28 Correct 234 ms 25924 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 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 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 17 ms 1376 KB Output is correct
9 Correct 234 ms 27384 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 13 ms 1428 KB Output is correct
13 Correct 244 ms 27500 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 972 KB Output is correct
17 Correct 119 ms 17464 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 65 ms 7236 KB Output is correct
22 Correct 234 ms 26892 KB Output is correct
23 Correct 238 ms 26788 KB Output is correct
24 Correct 258 ms 26872 KB Output is correct
25 Correct 101 ms 16932 KB Output is correct
26 Correct 122 ms 16908 KB Output is correct
27 Correct 248 ms 26780 KB Output is correct
28 Correct 247 ms 26904 KB Output is correct
29 Correct 99 ms 16900 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 1 ms 204 KB Output is correct
4 Correct 59 ms 6712 KB Output is correct
5 Correct 247 ms 25984 KB Output is correct
6 Correct 237 ms 25924 KB Output is correct
7 Correct 256 ms 25984 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 103 ms 6660 KB Output is correct
10 Correct 237 ms 25988 KB Output is correct
11 Correct 263 ms 25924 KB Output is correct
12 Correct 277 ms 25996 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 59 ms 6720 KB Output is correct
17 Correct 260 ms 25924 KB Output is correct
18 Correct 238 ms 25924 KB Output is correct
19 Correct 253 ms 25924 KB Output is correct
20 Correct 288 ms 25992 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 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 1356 KB Output is correct
7 Correct 250 ms 25992 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 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1356 KB Output is correct
13 Correct 246 ms 25968 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 844 KB Output is correct
17 Correct 119 ms 16268 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 61 ms 6660 KB Output is correct
21 Correct 241 ms 25904 KB Output is correct
22 Correct 238 ms 25924 KB Output is correct
23 Correct 255 ms 26100 KB Output is correct
24 Correct 232 ms 26004 KB Output is correct
25 Correct 105 ms 16068 KB Output is correct
26 Correct 97 ms 16144 KB Output is correct
27 Correct 256 ms 25924 KB Output is correct
28 Correct 234 ms 25924 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 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 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 17 ms 1376 KB Output is correct
37 Correct 234 ms 27384 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 13 ms 1428 KB Output is correct
41 Correct 244 ms 27500 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 972 KB Output is correct
45 Correct 119 ms 17464 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 65 ms 7236 KB Output is correct
50 Correct 234 ms 26892 KB Output is correct
51 Correct 238 ms 26788 KB Output is correct
52 Correct 258 ms 26872 KB Output is correct
53 Correct 101 ms 16932 KB Output is correct
54 Correct 122 ms 16908 KB Output is correct
55 Correct 248 ms 26780 KB Output is correct
56 Correct 247 ms 26904 KB Output is correct
57 Correct 99 ms 16900 KB Output is correct
58 Correct 1 ms 296 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 6 ms 972 KB Output is correct
61 Correct 122 ms 16920 KB Output is correct
62 Correct 2 ms 204 KB Output is correct
63 Correct 2 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 59 ms 7144 KB Output is correct
66 Correct 109 ms 17148 KB Output is correct
67 Correct 111 ms 17220 KB Output is correct
68 Correct 120 ms 17204 KB Output is correct
69 Correct 99 ms 17220 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 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 1356 KB Output is correct
7 Correct 250 ms 25992 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 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 10 ms 1356 KB Output is correct
13 Correct 246 ms 25968 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 844 KB Output is correct
17 Correct 119 ms 16268 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 61 ms 6660 KB Output is correct
21 Correct 241 ms 25904 KB Output is correct
22 Correct 238 ms 25924 KB Output is correct
23 Correct 255 ms 26100 KB Output is correct
24 Correct 232 ms 26004 KB Output is correct
25 Correct 105 ms 16068 KB Output is correct
26 Correct 97 ms 16144 KB Output is correct
27 Correct 256 ms 25924 KB Output is correct
28 Correct 234 ms 25924 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 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 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 17 ms 1376 KB Output is correct
37 Correct 234 ms 27384 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 13 ms 1428 KB Output is correct
41 Correct 244 ms 27500 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 972 KB Output is correct
45 Correct 119 ms 17464 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 65 ms 7236 KB Output is correct
50 Correct 234 ms 26892 KB Output is correct
51 Correct 238 ms 26788 KB Output is correct
52 Correct 258 ms 26872 KB Output is correct
53 Correct 101 ms 16932 KB Output is correct
54 Correct 122 ms 16908 KB Output is correct
55 Correct 248 ms 26780 KB Output is correct
56 Correct 247 ms 26904 KB Output is correct
57 Correct 99 ms 16900 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 59 ms 6712 KB Output is correct
62 Correct 247 ms 25984 KB Output is correct
63 Correct 237 ms 25924 KB Output is correct
64 Correct 256 ms 25984 KB Output is correct
65 Correct 2 ms 204 KB Output is correct
66 Correct 103 ms 6660 KB Output is correct
67 Correct 237 ms 25988 KB Output is correct
68 Correct 263 ms 25924 KB Output is correct
69 Correct 277 ms 25996 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 59 ms 6720 KB Output is correct
74 Correct 260 ms 25924 KB Output is correct
75 Correct 238 ms 25924 KB Output is correct
76 Correct 253 ms 25924 KB Output is correct
77 Correct 288 ms 25992 KB Output is correct
78 Correct 1 ms 296 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 6 ms 972 KB Output is correct
81 Correct 122 ms 16920 KB Output is correct
82 Correct 2 ms 204 KB Output is correct
83 Correct 2 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 59 ms 7144 KB Output is correct
86 Correct 109 ms 17148 KB Output is correct
87 Correct 111 ms 17220 KB Output is correct
88 Correct 120 ms 17204 KB Output is correct
89 Correct 99 ms 17220 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 300 KB Output is correct
92 Correct 5 ms 972 KB Output is correct
93 Correct 154 ms 17144 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 25 ms 4720 KB Output is correct
98 Correct 98 ms 17168 KB Output is correct
99 Correct 102 ms 17140 KB Output is correct
100 Correct 99 ms 17224 KB Output is correct
101 Correct 97 ms 17180 KB Output is correct
102 Correct 105 ms 17220 KB Output is correct
103 Correct 104 ms 17248 KB Output is correct
104 Correct 103 ms 17180 KB Output is correct
105 Correct 110 ms 17220 KB Output is correct