답안 #1071973

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1071973 2024-08-23T12:55:17 Z andrei_iorgulescu 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
148 ms 28088 KB
#include <bits/stdc++.h>
#include "supertrees.h"
#warning That's not FB, that's my FB

using namespace std;

int n;
vector<vector<int>> cc, cc2;
vector<int> cur;
vector<bool> viz;
vector<vector<int>> p;

void dfs(int nod)
{
    viz[nod] = true;
    cur.push_back(nod);
    for (int i = 0; i < n; i++)
    {
        if (i != nod and !viz[i] and p[nod][i] != 0)
            dfs(i);
    }
}

void dfs2(int nod)
{
    viz[nod] = true;
    cur.push_back(nod);
    for (int i = 0; i < n; i++)
    {
        if (i != nod and !viz[i] and p[nod][i] == 1)
            dfs2(i);
    }
}

int construct(vector<vector<int>> P)
{
    p = P;
    n = p.size();
    viz.resize(n);
    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++)
    {
        if (!viz[i])
        {
            cur.clear();
            dfs(i);
            cc.push_back(cur);
        }
    }
    for (auto it : cc)
    {
        for (auto itt : it)
            for (auto ittt : it)
                if (p[itt][ittt] == 0)
                    return 0;
    }
    vector<pair<int,int>> edges;
    for (int i = 0; i < n; i++)
        viz[i] = false;
    for (auto v : cc)
    {
        cc2.clear();
        for (auto it : v)
        {
            if (!viz[it])
            {
                cur.clear();
                dfs2(it);
                cc2.push_back(cur);
            }
        }
        for (auto vv : cc2)
        {
            /*for (auto it : vv)
                cout << it << ' ';
            cout << endl;*/
            for (auto it1 : vv)
            {
                for (auto it2 : vv)
                    if (p[it1][it2] != 1)
                        return 0;
            }
        }
        if (cc2.size() == 2)
            return 0;
        if (cc2.size() == 1)
        {
            for (int i = 0; i + 1 < v.size(); i++)
                edges.push_back({v[i], v[i + 1]});
        }
        else if (cc2.size() >= 3)
        {
            for (auto vv : cc2)
            {
                for (int i = 0; i + 1 < vv.size(); i++)
                    edges.push_back({vv[i], vv[i + 1]});
            }
            for (int i = 0; i < cc2.size(); i++)
                edges.push_back({cc2[i][0], cc2[(i + 1) % (int)cc2.size()][0]});
        }
    }
    vector<vector<int>> bld(n);
    for (int i = 0; i < n; i++)
        bld[i].resize(n);
    for (auto it : edges)
        bld[it.first][it.second] = bld[it.second][it.first] = 1;
    build(bld);
    return 1;
}

Compilation message

supertrees.cpp:3:2: warning: #warning That's not FB, that's my FB [-Wcpp]
    3 | #warning That's not FB, that's my FB
      |  ^~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:91:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |             for (int i = 0; i + 1 < v.size(); i++)
      |                             ~~~~~~^~~~~~~~~~
supertrees.cpp:98:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |                 for (int i = 0; i + 1 < vv.size(); i++)
      |                                 ~~~~~~^~~~~~~~~~~
supertrees.cpp:101:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |             for (int i = 0; i < cc2.size(); i++)
      |                             ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 123 ms 27960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 123 ms 27960 KB Output is correct
8 Correct 1 ms 412 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 117 ms 27988 KB Output is correct
14 Correct 0 ms 596 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 936 KB Output is correct
17 Correct 63 ms 14084 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 7300 KB Output is correct
21 Correct 147 ms 27892 KB Output is correct
22 Correct 123 ms 28016 KB Output is correct
23 Correct 129 ms 27988 KB Output is correct
24 Correct 119 ms 28072 KB Output is correct
25 Correct 67 ms 14160 KB Output is correct
26 Correct 56 ms 14092 KB Output is correct
27 Correct 124 ms 27988 KB Output is correct
28 Correct 121 ms 27988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1508 KB Output is correct
9 Correct 121 ms 27908 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1536 KB Output is correct
13 Correct 123 ms 28040 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 58 ms 14196 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 392 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 30 ms 7260 KB Output is correct
22 Correct 135 ms 27896 KB Output is correct
23 Correct 124 ms 27984 KB Output is correct
24 Correct 138 ms 27984 KB Output is correct
25 Correct 52 ms 14164 KB Output is correct
26 Correct 56 ms 14160 KB Output is correct
27 Correct 123 ms 27984 KB Output is correct
28 Correct 148 ms 27984 KB Output is correct
29 Correct 56 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 31 ms 7296 KB Output is correct
5 Correct 118 ms 28088 KB Output is correct
6 Correct 117 ms 27988 KB Output is correct
7 Correct 128 ms 27988 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 30 ms 7224 KB Output is correct
10 Correct 129 ms 27912 KB Output is correct
11 Correct 114 ms 27988 KB Output is correct
12 Correct 125 ms 28076 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 37 ms 7292 KB Output is correct
17 Correct 119 ms 28044 KB Output is correct
18 Correct 117 ms 28036 KB Output is correct
19 Correct 119 ms 27984 KB Output is correct
20 Correct 125 ms 27984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 123 ms 27960 KB Output is correct
8 Correct 1 ms 412 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 117 ms 27988 KB Output is correct
14 Correct 0 ms 596 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 936 KB Output is correct
17 Correct 63 ms 14084 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 7300 KB Output is correct
21 Correct 147 ms 27892 KB Output is correct
22 Correct 123 ms 28016 KB Output is correct
23 Correct 129 ms 27988 KB Output is correct
24 Correct 119 ms 28072 KB Output is correct
25 Correct 67 ms 14160 KB Output is correct
26 Correct 56 ms 14092 KB Output is correct
27 Correct 124 ms 27988 KB Output is correct
28 Correct 121 ms 27988 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1508 KB Output is correct
37 Correct 121 ms 27908 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 6 ms 1536 KB Output is correct
41 Correct 123 ms 28040 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 58 ms 14196 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 392 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 30 ms 7260 KB Output is correct
50 Correct 135 ms 27896 KB Output is correct
51 Correct 124 ms 27984 KB Output is correct
52 Correct 138 ms 27984 KB Output is correct
53 Correct 52 ms 14164 KB Output is correct
54 Correct 56 ms 14160 KB Output is correct
55 Correct 123 ms 27984 KB Output is correct
56 Correct 148 ms 27984 KB Output is correct
57 Correct 56 ms 14160 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 3 ms 860 KB Output is correct
61 Correct 56 ms 14164 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 29 ms 7364 KB Output is correct
66 Correct 53 ms 14160 KB Output is correct
67 Correct 63 ms 14152 KB Output is correct
68 Correct 53 ms 14216 KB Output is correct
69 Correct 61 ms 14164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 123 ms 27960 KB Output is correct
8 Correct 1 ms 412 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 117 ms 27988 KB Output is correct
14 Correct 0 ms 596 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 936 KB Output is correct
17 Correct 63 ms 14084 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 7300 KB Output is correct
21 Correct 147 ms 27892 KB Output is correct
22 Correct 123 ms 28016 KB Output is correct
23 Correct 129 ms 27988 KB Output is correct
24 Correct 119 ms 28072 KB Output is correct
25 Correct 67 ms 14160 KB Output is correct
26 Correct 56 ms 14092 KB Output is correct
27 Correct 124 ms 27988 KB Output is correct
28 Correct 121 ms 27988 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1508 KB Output is correct
37 Correct 121 ms 27908 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 6 ms 1536 KB Output is correct
41 Correct 123 ms 28040 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 58 ms 14196 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 392 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 30 ms 7260 KB Output is correct
50 Correct 135 ms 27896 KB Output is correct
51 Correct 124 ms 27984 KB Output is correct
52 Correct 138 ms 27984 KB Output is correct
53 Correct 52 ms 14164 KB Output is correct
54 Correct 56 ms 14160 KB Output is correct
55 Correct 123 ms 27984 KB Output is correct
56 Correct 148 ms 27984 KB Output is correct
57 Correct 56 ms 14160 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 31 ms 7296 KB Output is correct
62 Correct 118 ms 28088 KB Output is correct
63 Correct 117 ms 27988 KB Output is correct
64 Correct 128 ms 27988 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 30 ms 7224 KB Output is correct
67 Correct 129 ms 27912 KB Output is correct
68 Correct 114 ms 27988 KB Output is correct
69 Correct 125 ms 28076 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 0 ms 604 KB Output is correct
73 Correct 37 ms 7292 KB Output is correct
74 Correct 119 ms 28044 KB Output is correct
75 Correct 117 ms 28036 KB Output is correct
76 Correct 119 ms 27984 KB Output is correct
77 Correct 125 ms 27984 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 344 KB Output is correct
80 Correct 3 ms 860 KB Output is correct
81 Correct 56 ms 14164 KB Output is correct
82 Correct 1 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 29 ms 7364 KB Output is correct
86 Correct 53 ms 14160 KB Output is correct
87 Correct 63 ms 14152 KB Output is correct
88 Correct 53 ms 14216 KB Output is correct
89 Correct 61 ms 14164 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 3 ms 860 KB Output is correct
93 Correct 51 ms 13996 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 12 ms 3712 KB Output is correct
98 Correct 52 ms 14200 KB Output is correct
99 Correct 55 ms 13996 KB Output is correct
100 Correct 51 ms 14160 KB Output is correct
101 Correct 50 ms 14212 KB Output is correct
102 Correct 50 ms 14164 KB Output is correct
103 Correct 49 ms 14164 KB Output is correct
104 Correct 51 ms 14164 KB Output is correct
105 Correct 56 ms 14084 KB Output is correct