답안 #300744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300744 2020-09-17T13:01:27 Z IgorI 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
303 ms 22264 KB
#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)

void build(vector<vector<int> > b) ;

void build(vector<vector<int> > b) ;

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] > sz[u]) swap(v, u);
    sz[u] += sz[v];
    root[v] = u;
}

int construct(vector<vector<int> > p)
{
    int n = p.size();
    vector<int> root(n), sz(n);
    for (int i = 0; i < n; i++) root[i] = i, sz[i] = 1;
    int t = 0;
    forn(i, n)
    {
        forn(j, n)
        {
            if (p[i][j] == 3)
            {
                return 0;
            }
            if (p[i][j])
            {
                Merge(i, j, root, sz);
            }
        }
    }
    forn(i, n)
    {
        forn(j, n)
        {
            if (Root(i, root) == Root(j, root) && p[i][j] == 0)
            {
                return 0;
            }
        }
    }
    vector<vector<int> > b(n, vector<int>(n));
    forn(i, n)
    {
        vector<int> L;
        forn(j, n)
        {
            if (Root(j, root) == i)
            {
                L.push_back(j);
            }
        }
        vector<int> root2(L.size()), sz2(L.size());
        iota(root2.begin(), root2.end(), 0);
        fill(sz2.begin(), sz2.end(), 1);
        for (int a = 0; a < L.size(); a++)
        {
            for (int b = 0; b < L.size(); b++)
            {
                if (p[L[a]][L[b]] == 1)
                {
                    Merge(a, b, root2, sz2);
                }
            }
        }
        for (int a = 0; a < L.size(); a++)
        {
            for (int b = 0; b < L.size(); b++)
            {
                if (p[L[a]][L[b]] == 2 && Root(a, root2) == Root(b, root2))
                    return 0;
            }
        }
        vector<vector<int> > z(L.size());
        for (int a = 0; a < L.size(); a++)
        {
            z[Root(a, root2)].push_back(L[a]);
        }
        vector<int> q;
        for (int j = 0; j < z.size(); j++)
        {
            if (z[j].size()) q.push_back(z[j][0]);
            for (int e = 0; e + 1 < z[j].size(); e++)
            {
                b[z[j][e]][z[j][e + 1]] = 1;
                b[z[j][e + 1]][z[j][e]] = 1;
            }
        }
        if (q.size() == 2)
        {
            return 0;
        }
        if (q.size() > 2)
        for (int i = 0; i < q.size(); i++)
        {
            b[q[i]][q[(i + 1) % q.size()]] = 1;
            b[q[(i + 1) % q.size()]][q[i]] = 1;
        }
    }
    build(b);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:5:29: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
      |                             ^
supertrees.cpp:32:5: note: in expansion of macro 'forn'
   32 |     forn(i, n)
      |     ^~~~
supertrees.cpp:5:29: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    5 | #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
      |                             ^
supertrees.cpp:34:9: note: in expansion of macro 'forn'
   34 |         forn(j, n)
      |         ^~~~
supertrees.cpp:5:29: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
      |                             ^
supertrees.cpp:46:5: note: in expansion of macro 'forn'
   46 |     forn(i, n)
      |     ^~~~
supertrees.cpp:5:29: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    5 | #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
      |                             ^
supertrees.cpp:48:9: note: in expansion of macro 'forn'
   48 |         forn(j, n)
      |         ^~~~
supertrees.cpp:5:29: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
      |                             ^
supertrees.cpp:57:5: note: in expansion of macro 'forn'
   57 |     forn(i, n)
      |     ^~~~
supertrees.cpp:5:29: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    5 | #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
      |                             ^
supertrees.cpp:60:9: note: in expansion of macro 'forn'
   60 |         forn(j, n)
      |         ^~~~
supertrees.cpp:70:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for (int a = 0; a < L.size(); a++)
      |                         ~~^~~~~~~~~~
supertrees.cpp:72:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |             for (int b = 0; b < L.size(); b++)
      |                             ~~^~~~~~~~~~
supertrees.cpp:80:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         for (int a = 0; a < L.size(); a++)
      |                         ~~^~~~~~~~~~
supertrees.cpp:82:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |             for (int b = 0; b < L.size(); b++)
      |                             ~~^~~~~~~~~~
supertrees.cpp:89:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for (int a = 0; a < L.size(); a++)
      |                         ~~^~~~~~~~~~
supertrees.cpp:94:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         for (int j = 0; j < z.size(); j++)
      |                         ~~^~~~~~~~~~
supertrees.cpp:97:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |             for (int e = 0; e + 1 < z[j].size(); e++)
      |                             ~~~~~~^~~~~~~~~~~~~
supertrees.cpp:108:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |         for (int i = 0; i < q.size(); i++)
      |                         ~~^~~~~~~~~~
supertrees.cpp:31:9: warning: unused variable 't' [-Wunused-variable]
   31 |     int t = 0;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 12 ms 1152 KB Output is correct
7 Correct 293 ms 22104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 12 ms 1152 KB Output is correct
7 Correct 293 ms 22104 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 247 ms 22100 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 119 ms 8184 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 66 ms 5752 KB Output is correct
21 Correct 301 ms 22264 KB Output is correct
22 Correct 267 ms 22136 KB Output is correct
23 Correct 303 ms 22144 KB Output is correct
24 Correct 248 ms 22264 KB Output is correct
25 Correct 100 ms 8184 KB Output is correct
26 Correct 97 ms 8184 KB Output is correct
27 Correct 291 ms 22104 KB Output is correct
28 Correct 255 ms 22104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 10 ms 1152 KB Output is correct
9 Correct 249 ms 22104 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 12 ms 1152 KB Output is correct
13 Correct 285 ms 22096 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 128 ms 8184 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 68 ms 5752 KB Output is correct
22 Correct 258 ms 22136 KB Output is correct
23 Correct 264 ms 22136 KB Output is correct
24 Correct 291 ms 22136 KB Output is correct
25 Correct 109 ms 12108 KB Output is correct
26 Correct 101 ms 8184 KB Output is correct
27 Correct 262 ms 22136 KB Output is correct
28 Correct 299 ms 22100 KB Output is correct
29 Correct 110 ms 12108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 64 ms 5752 KB Output is correct
5 Correct 273 ms 22104 KB Output is correct
6 Correct 271 ms 22136 KB Output is correct
7 Correct 290 ms 22136 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 75 ms 5752 KB Output is correct
10 Correct 260 ms 22136 KB Output is correct
11 Correct 260 ms 22136 KB Output is correct
12 Correct 282 ms 22136 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 69 ms 5756 KB Output is correct
17 Correct 259 ms 22136 KB Output is correct
18 Correct 268 ms 22136 KB Output is correct
19 Correct 263 ms 22136 KB Output is correct
20 Correct 250 ms 22136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 12 ms 1152 KB Output is correct
7 Correct 293 ms 22104 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 247 ms 22100 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 119 ms 8184 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 66 ms 5752 KB Output is correct
21 Correct 301 ms 22264 KB Output is correct
22 Correct 267 ms 22136 KB Output is correct
23 Correct 303 ms 22144 KB Output is correct
24 Correct 248 ms 22264 KB Output is correct
25 Correct 100 ms 8184 KB Output is correct
26 Correct 97 ms 8184 KB Output is correct
27 Correct 291 ms 22104 KB Output is correct
28 Correct 255 ms 22104 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 0 ms 256 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 256 KB Output is correct
36 Correct 10 ms 1152 KB Output is correct
37 Correct 249 ms 22104 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 12 ms 1152 KB Output is correct
41 Correct 285 ms 22096 KB Output is correct
42 Correct 0 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 5 ms 640 KB Output is correct
45 Correct 128 ms 8184 KB Output is correct
46 Correct 0 ms 256 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 68 ms 5752 KB Output is correct
50 Correct 258 ms 22136 KB Output is correct
51 Correct 264 ms 22136 KB Output is correct
52 Correct 291 ms 22136 KB Output is correct
53 Correct 109 ms 12108 KB Output is correct
54 Correct 101 ms 8184 KB Output is correct
55 Correct 262 ms 22136 KB Output is correct
56 Correct 299 ms 22100 KB Output is correct
57 Correct 110 ms 12108 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 5 ms 640 KB Output is correct
61 Correct 117 ms 8184 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 256 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Correct 67 ms 5752 KB Output is correct
66 Correct 100 ms 8184 KB Output is correct
67 Correct 101 ms 8152 KB Output is correct
68 Correct 98 ms 8184 KB Output is correct
69 Correct 105 ms 12156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 12 ms 1152 KB Output is correct
7 Correct 293 ms 22104 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 247 ms 22100 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 119 ms 8184 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 66 ms 5752 KB Output is correct
21 Correct 301 ms 22264 KB Output is correct
22 Correct 267 ms 22136 KB Output is correct
23 Correct 303 ms 22144 KB Output is correct
24 Correct 248 ms 22264 KB Output is correct
25 Correct 100 ms 8184 KB Output is correct
26 Correct 97 ms 8184 KB Output is correct
27 Correct 291 ms 22104 KB Output is correct
28 Correct 255 ms 22104 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 0 ms 256 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 256 KB Output is correct
36 Correct 10 ms 1152 KB Output is correct
37 Correct 249 ms 22104 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 12 ms 1152 KB Output is correct
41 Correct 285 ms 22096 KB Output is correct
42 Correct 0 ms 256 KB Output is correct
43 Correct 1 ms 256 KB Output is correct
44 Correct 5 ms 640 KB Output is correct
45 Correct 128 ms 8184 KB Output is correct
46 Correct 0 ms 256 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 68 ms 5752 KB Output is correct
50 Correct 258 ms 22136 KB Output is correct
51 Correct 264 ms 22136 KB Output is correct
52 Correct 291 ms 22136 KB Output is correct
53 Correct 109 ms 12108 KB Output is correct
54 Correct 101 ms 8184 KB Output is correct
55 Correct 262 ms 22136 KB Output is correct
56 Correct 299 ms 22100 KB Output is correct
57 Correct 110 ms 12108 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 1 ms 256 KB Output is correct
61 Correct 64 ms 5752 KB Output is correct
62 Correct 273 ms 22104 KB Output is correct
63 Correct 271 ms 22136 KB Output is correct
64 Correct 290 ms 22136 KB Output is correct
65 Correct 1 ms 256 KB Output is correct
66 Correct 75 ms 5752 KB Output is correct
67 Correct 260 ms 22136 KB Output is correct
68 Correct 260 ms 22136 KB Output is correct
69 Correct 282 ms 22136 KB Output is correct
70 Correct 1 ms 256 KB Output is correct
71 Correct 0 ms 256 KB Output is correct
72 Correct 0 ms 256 KB Output is correct
73 Correct 69 ms 5756 KB Output is correct
74 Correct 259 ms 22136 KB Output is correct
75 Correct 268 ms 22136 KB Output is correct
76 Correct 263 ms 22136 KB Output is correct
77 Correct 250 ms 22136 KB Output is correct
78 Correct 0 ms 256 KB Output is correct
79 Correct 0 ms 256 KB Output is correct
80 Correct 5 ms 640 KB Output is correct
81 Correct 117 ms 8184 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 256 KB Output is correct
84 Correct 1 ms 256 KB Output is correct
85 Correct 67 ms 5752 KB Output is correct
86 Correct 100 ms 8184 KB Output is correct
87 Correct 101 ms 8152 KB Output is correct
88 Correct 98 ms 8184 KB Output is correct
89 Correct 105 ms 12156 KB Output is correct
90 Correct 0 ms 256 KB Output is correct
91 Correct 1 ms 256 KB Output is correct
92 Correct 4 ms 640 KB Output is correct
93 Correct 99 ms 8184 KB Output is correct
94 Correct 0 ms 256 KB Output is correct
95 Correct 0 ms 256 KB Output is correct
96 Correct 1 ms 256 KB Output is correct
97 Correct 24 ms 2296 KB Output is correct
98 Correct 109 ms 8152 KB Output is correct
99 Correct 98 ms 8184 KB Output is correct
100 Correct 95 ms 8184 KB Output is correct
101 Correct 96 ms 8184 KB Output is correct
102 Correct 97 ms 8184 KB Output is correct
103 Correct 100 ms 8184 KB Output is correct
104 Correct 97 ms 8184 KB Output is correct
105 Correct 108 ms 8184 KB Output is correct