답안 #398432

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398432 2021-05-04T09:13:11 Z iulia13 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
278 ms 30212 KB
#include <iostream>
#include <vector>
#include "supertrees.h"
using namespace std;
#define pb push_back
const int nmax = 1005;
vector <int> comp;
vector <int> comp2;
vector <int> ciclu;
vector <int> g[nmax];
vector <int> G[nmax];
int viz[nmax], viz2[nmax], viz3[nmax];
void dfs(int nod)
{
    comp.pb(nod);
    viz[nod] = 1;
    for (auto x : g[nod])
        if (!viz[x])
            dfs(x);
}
void dfs2(int nod)
{
    comp2.pb(nod);
    viz2[nod] = 1;
    for (auto x : G[nod])
        if (!viz2[x])
            dfs2(x);
}/*
void build(vector < vector <int> > ans)
{
    int n = ans.size();
    for (int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
            cout << ans[i][j] << " ";
        cout << endl;
    }
}*/
int construct (vector < vector <int> > p)
{
    int n = p.size();
    vector<vector<int>> ans;
    ans.resize(n);
    int i, j;
    for (i = 0; i < n; i++)
    {
        ans[i].resize(n);
        for (j = i + 1; j < n; j++)
        {
            if (p[i][j] == 3)
                return 0;
            if (p[i][j])
            {
                g[i].pb(j);
                g[j].pb(i);
            }
        }
    }
    for (int iii = 0; iii < n; iii++)
    {
        if (viz[iii])
            continue;
        ciclu.clear();
        comp.clear();
        dfs(iii);
        int x = comp.size();
        for (i = 0; i < x; i++)
            for (j = 1 + i; j < x; j++)
            {
                int ii = comp[i];
                int jj = comp[j];
                if (!p[ii][jj])
                    return 0;
                if (p[ii][jj] == 1)
                {
                    G[ii].pb(jj);
                    G[jj].pb(ii);
                }
            }
        for (int ii = 0; ii < x; ii++)
        {
            i = comp[ii];
            if (viz2[i])
                continue;
            comp2.clear();
            dfs2(i);
            int x2 = comp2.size();
            for (auto nod : comp2)
                viz3[nod] = 1;
            for (auto a : comp2)
                for (auto b : comp)
                {
                    if (viz3[b] && p[a][b] != 1)
                        return 0;
                    if (!viz3[b] && p[a][b] != 2)
                        return 0;
                }
         	for (auto nod : comp2)
                viz3[nod] = 0;
            for (i = 0; i < x2 - 1; i++)
            {
                int a = comp2[i];
                int b = comp2[i + 1];
                ans[a][b] = 1;
                ans[b][a] = 1;
            }
            ciclu.pb(comp2[0]);
        }
        int x2 = ciclu.size();
        if (x2 == 2)
            return 0;
        if (x2 < 2)
            continue;
        for (i = 0; i < x2 - 1; i++)
        {
            ans[ciclu[i]][ciclu[i + 1]] = 1;
            ans[ciclu[i + 1]][ciclu[i]] = 1;
        }
        x2--;
        ans[ciclu[0]][ciclu[x2]] = 1;
        ans[ciclu[x2]][ciclu[0]] = 1;
    }
    build(ans);
    return 1;
}/*
int main()
{
    int n, i, j;
    cin >> n;
    vector <vector <int>> p;
    p.resize(n);
    for (i = 0; i < n; i++)
        p[i].resize(n);
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            cin >> p[i][j];
    construct(p);
    return 0;
}
*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:90:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   90 |             for (auto a : comp2)
      |             ^~~
supertrees.cpp:98:11: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   98 |           for (auto nod : comp2)
      |           ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1612 KB Output is correct
7 Correct 264 ms 30212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1612 KB Output is correct
7 Correct 264 ms 30212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 248 ms 22076 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 972 KB Output is correct
17 Correct 119 ms 15040 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 68 ms 5828 KB Output is correct
21 Correct 258 ms 23124 KB Output is correct
22 Correct 241 ms 22064 KB Output is correct
23 Correct 259 ms 26180 KB Output is correct
24 Correct 249 ms 22108 KB Output is correct
25 Correct 106 ms 12992 KB Output is correct
26 Correct 105 ms 12208 KB Output is correct
27 Correct 259 ms 28220 KB Output is correct
28 Correct 278 ms 22092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 10 ms 1232 KB Output is correct
9 Correct 238 ms 22132 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1452 KB Output is correct
13 Correct 256 ms 26172 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1024 KB Output is correct
17 Correct 117 ms 15040 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 60 ms 5852 KB Output is correct
22 Correct 260 ms 22656 KB Output is correct
23 Correct 243 ms 22084 KB Output is correct
24 Correct 254 ms 25228 KB Output is correct
25 Correct 107 ms 12092 KB Output is correct
26 Correct 106 ms 12728 KB Output is correct
27 Correct 244 ms 22076 KB Output is correct
28 Correct 261 ms 24116 KB Output is correct
29 Correct 104 ms 12100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 62 ms 5876 KB Output is correct
5 Correct 248 ms 23160 KB Output is correct
6 Correct 238 ms 22156 KB Output is correct
7 Correct 265 ms 26284 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 71 ms 5856 KB Output is correct
10 Correct 266 ms 22716 KB Output is correct
11 Correct 241 ms 22032 KB Output is correct
12 Correct 260 ms 25360 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 63 ms 6316 KB Output is correct
17 Correct 247 ms 24512 KB Output is correct
18 Correct 245 ms 24608 KB Output is correct
19 Correct 246 ms 24288 KB Output is correct
20 Correct 241 ms 23972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1612 KB Output is correct
7 Correct 264 ms 30212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 248 ms 22076 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 972 KB Output is correct
17 Correct 119 ms 15040 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 68 ms 5828 KB Output is correct
21 Correct 258 ms 23124 KB Output is correct
22 Correct 241 ms 22064 KB Output is correct
23 Correct 259 ms 26180 KB Output is correct
24 Correct 249 ms 22108 KB Output is correct
25 Correct 106 ms 12992 KB Output is correct
26 Correct 105 ms 12208 KB Output is correct
27 Correct 259 ms 28220 KB Output is correct
28 Correct 278 ms 22092 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 10 ms 1232 KB Output is correct
37 Correct 238 ms 22132 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 11 ms 1452 KB Output is correct
41 Correct 256 ms 26172 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 6 ms 1024 KB Output is correct
45 Correct 117 ms 15040 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 60 ms 5852 KB Output is correct
50 Correct 260 ms 22656 KB Output is correct
51 Correct 243 ms 22084 KB Output is correct
52 Correct 254 ms 25228 KB Output is correct
53 Correct 107 ms 12092 KB Output is correct
54 Correct 106 ms 12728 KB Output is correct
55 Correct 244 ms 22076 KB Output is correct
56 Correct 261 ms 24116 KB Output is correct
57 Correct 104 ms 12100 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 6 ms 972 KB Output is correct
61 Correct 122 ms 16708 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 68 ms 5776 KB Output is correct
66 Correct 108 ms 14764 KB Output is correct
67 Correct 111 ms 14628 KB Output is correct
68 Correct 104 ms 14276 KB Output is correct
69 Correct 103 ms 14148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1612 KB Output is correct
7 Correct 264 ms 30212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1228 KB Output is correct
13 Correct 248 ms 22076 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 972 KB Output is correct
17 Correct 119 ms 15040 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 68 ms 5828 KB Output is correct
21 Correct 258 ms 23124 KB Output is correct
22 Correct 241 ms 22064 KB Output is correct
23 Correct 259 ms 26180 KB Output is correct
24 Correct 249 ms 22108 KB Output is correct
25 Correct 106 ms 12992 KB Output is correct
26 Correct 105 ms 12208 KB Output is correct
27 Correct 259 ms 28220 KB Output is correct
28 Correct 278 ms 22092 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 10 ms 1232 KB Output is correct
37 Correct 238 ms 22132 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 11 ms 1452 KB Output is correct
41 Correct 256 ms 26172 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 6 ms 1024 KB Output is correct
45 Correct 117 ms 15040 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 60 ms 5852 KB Output is correct
50 Correct 260 ms 22656 KB Output is correct
51 Correct 243 ms 22084 KB Output is correct
52 Correct 254 ms 25228 KB Output is correct
53 Correct 107 ms 12092 KB Output is correct
54 Correct 106 ms 12728 KB Output is correct
55 Correct 244 ms 22076 KB Output is correct
56 Correct 261 ms 24116 KB Output is correct
57 Correct 104 ms 12100 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 62 ms 5876 KB Output is correct
62 Correct 248 ms 23160 KB Output is correct
63 Correct 238 ms 22156 KB Output is correct
64 Correct 265 ms 26284 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 71 ms 5856 KB Output is correct
67 Correct 266 ms 22716 KB Output is correct
68 Correct 241 ms 22032 KB Output is correct
69 Correct 260 ms 25360 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 332 KB Output is correct
73 Correct 63 ms 6316 KB Output is correct
74 Correct 247 ms 24512 KB Output is correct
75 Correct 245 ms 24608 KB Output is correct
76 Correct 246 ms 24288 KB Output is correct
77 Correct 241 ms 23972 KB Output is correct
78 Correct 1 ms 332 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 6 ms 972 KB Output is correct
81 Correct 122 ms 16708 KB Output is correct
82 Correct 1 ms 332 KB Output is correct
83 Correct 1 ms 332 KB Output is correct
84 Correct 1 ms 332 KB Output is correct
85 Correct 68 ms 5776 KB Output is correct
86 Correct 108 ms 14764 KB Output is correct
87 Correct 111 ms 14628 KB Output is correct
88 Correct 104 ms 14276 KB Output is correct
89 Correct 103 ms 14148 KB Output is correct
90 Correct 1 ms 348 KB Output is correct
91 Correct 1 ms 332 KB Output is correct
92 Correct 5 ms 716 KB Output is correct
93 Correct 108 ms 10148 KB Output is correct
94 Correct 1 ms 332 KB Output is correct
95 Correct 1 ms 336 KB Output is correct
96 Correct 1 ms 336 KB Output is correct
97 Correct 25 ms 2884 KB Output is correct
98 Correct 102 ms 10468 KB Output is correct
99 Correct 120 ms 10928 KB Output is correct
100 Correct 113 ms 10568 KB Output is correct
101 Correct 101 ms 11440 KB Output is correct
102 Correct 100 ms 10196 KB Output is correct
103 Correct 105 ms 10148 KB Output is correct
104 Correct 101 ms 10160 KB Output is correct
105 Correct 107 ms 10204 KB Output is correct