Submission #554379

# Submission time Handle Problem Language Result Execution time Memory
554379 2022-04-28T10:18:07 Z n0sk1ll Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
231 ms 24268 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

int up[1003];
vector<int> chain[1003];
vector<int> head;
vector<int> kompofheads[1003];

int Up(int x)
{
    if (up[x]<0) return x;
    return up[x]=Up(up[x]);
}

void dsu(int a, int b)
{
    a=Up(a),b=Up(b);
    if (a==b) return;
    up[a]=b;
}

vector<vector<int>> ans;

void add(int i, int j)
{
    ans[i][j]=1,ans[j][i]=1;
}

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

	for (int i=0;i<n;i++)
    {
        vector<int> pom(n,0);
        ans.push_back(pom);
    }

	for (int i=0;i<n;i++)
        if (p[i][i]!=1) return 0;

	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++) up[i]=-1;
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            if (p[i][j]==1) dsu(i,j);

    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            if (Up(i)==Up(j) && p[i][j]!=1) return 0;

    for (int i=0;i<n;i++) chain[Up(i)].push_back(i);
    for (int i=0;i<n;i++) if (up[i]<0) head.push_back(i);

    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            if (p[i][j]) dsu(i,j);

    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            if (Up(i)==Up(j) && !p[i][j]) return 0;

    for (int i=0;i<head.size();i++)
        kompofheads[Up(head[i])].push_back(head[i]);

    for (int i=0;i<n;i++)
    {
        if (kompofheads[i].size()==2) return 0;
        if (kompofheads[i].size()>2)
        {
            for (int j=1;j<kompofheads[i].size();j++) add(kompofheads[i][j-1],kompofheads[i][j]);
            add(kompofheads[i].front(),kompofheads[i].back());
        }
    }

    for (int i=0;i<n;i++)
        for (int j=1;j<chain[i].size();j++)
            add(chain[i][j-1],chain[i][j]);

	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:68:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for (int i=0;i<head.size();i++)
      |                  ~^~~~~~~~~~~~
supertrees.cpp:76:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             for (int j=1;j<kompofheads[i].size();j++) add(kompofheads[i][j-1],kompofheads[i][j]);
      |                          ~^~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:82:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for (int j=1;j<chain[i].size();j++)
      |                      ~^~~~~~~~~~~~~~~~
supertrees.cpp:81:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   81 |     for (int i=0;i<n;i++)
      |     ^~~
supertrees.cpp:85:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   85 |  build(ans);
      |  ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 1236 KB Output is correct
7 Correct 189 ms 24104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 1236 KB Output is correct
7 Correct 189 ms 24104 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 11 ms 1232 KB Output is correct
13 Correct 196 ms 24112 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 88 ms 14128 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 49 ms 6312 KB Output is correct
21 Correct 209 ms 24012 KB Output is correct
22 Correct 231 ms 24040 KB Output is correct
23 Correct 227 ms 24000 KB Output is correct
24 Correct 192 ms 24056 KB Output is correct
25 Correct 85 ms 14032 KB Output is correct
26 Correct 71 ms 14132 KB Output is correct
27 Correct 207 ms 24012 KB Output is correct
28 Correct 183 ms 24232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 9 ms 1340 KB Output is correct
9 Correct 200 ms 24196 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 356 KB Output is correct
12 Correct 9 ms 1256 KB Output is correct
13 Correct 200 ms 24008 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 86 ms 14132 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 45 ms 6292 KB Output is correct
22 Correct 204 ms 24100 KB Output is correct
23 Correct 187 ms 23992 KB Output is correct
24 Correct 187 ms 24028 KB Output is correct
25 Correct 117 ms 14160 KB Output is correct
26 Correct 76 ms 14120 KB Output is correct
27 Correct 186 ms 24104 KB Output is correct
28 Correct 211 ms 24108 KB Output is correct
29 Correct 80 ms 14156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 48 ms 6312 KB Output is correct
5 Correct 201 ms 24060 KB Output is correct
6 Correct 189 ms 23988 KB Output is correct
7 Correct 209 ms 24108 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 46 ms 6316 KB Output is correct
10 Correct 191 ms 24084 KB Output is correct
11 Correct 183 ms 23996 KB Output is correct
12 Correct 212 ms 24056 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 45 ms 6300 KB Output is correct
17 Correct 178 ms 24036 KB Output is correct
18 Correct 198 ms 23972 KB Output is correct
19 Correct 190 ms 23976 KB Output is correct
20 Correct 209 ms 24268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 1236 KB Output is correct
7 Correct 189 ms 24104 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 11 ms 1232 KB Output is correct
13 Correct 196 ms 24112 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 88 ms 14128 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 49 ms 6312 KB Output is correct
21 Correct 209 ms 24012 KB Output is correct
22 Correct 231 ms 24040 KB Output is correct
23 Correct 227 ms 24000 KB Output is correct
24 Correct 192 ms 24056 KB Output is correct
25 Correct 85 ms 14032 KB Output is correct
26 Correct 71 ms 14132 KB Output is correct
27 Correct 207 ms 24012 KB Output is correct
28 Correct 183 ms 24232 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 288 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 9 ms 1340 KB Output is correct
37 Correct 200 ms 24196 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 356 KB Output is correct
40 Correct 9 ms 1256 KB Output is correct
41 Correct 200 ms 24008 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 86 ms 14132 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 45 ms 6292 KB Output is correct
50 Correct 204 ms 24100 KB Output is correct
51 Correct 187 ms 23992 KB Output is correct
52 Correct 187 ms 24028 KB Output is correct
53 Correct 117 ms 14160 KB Output is correct
54 Correct 76 ms 14120 KB Output is correct
55 Correct 186 ms 24104 KB Output is correct
56 Correct 211 ms 24108 KB Output is correct
57 Correct 80 ms 14156 KB Output is correct
58 Correct 1 ms 352 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 4 ms 876 KB Output is correct
61 Correct 88 ms 14136 KB Output is correct
62 Correct 1 ms 352 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 61 ms 6304 KB Output is correct
66 Correct 75 ms 14156 KB Output is correct
67 Correct 70 ms 14120 KB Output is correct
68 Correct 78 ms 14124 KB Output is correct
69 Correct 85 ms 14124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 9 ms 1236 KB Output is correct
7 Correct 189 ms 24104 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 11 ms 1232 KB Output is correct
13 Correct 196 ms 24112 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 88 ms 14128 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 49 ms 6312 KB Output is correct
21 Correct 209 ms 24012 KB Output is correct
22 Correct 231 ms 24040 KB Output is correct
23 Correct 227 ms 24000 KB Output is correct
24 Correct 192 ms 24056 KB Output is correct
25 Correct 85 ms 14032 KB Output is correct
26 Correct 71 ms 14132 KB Output is correct
27 Correct 207 ms 24012 KB Output is correct
28 Correct 183 ms 24232 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 288 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 9 ms 1340 KB Output is correct
37 Correct 200 ms 24196 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 356 KB Output is correct
40 Correct 9 ms 1256 KB Output is correct
41 Correct 200 ms 24008 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 86 ms 14132 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 45 ms 6292 KB Output is correct
50 Correct 204 ms 24100 KB Output is correct
51 Correct 187 ms 23992 KB Output is correct
52 Correct 187 ms 24028 KB Output is correct
53 Correct 117 ms 14160 KB Output is correct
54 Correct 76 ms 14120 KB Output is correct
55 Correct 186 ms 24104 KB Output is correct
56 Correct 211 ms 24108 KB Output is correct
57 Correct 80 ms 14156 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 48 ms 6312 KB Output is correct
62 Correct 201 ms 24060 KB Output is correct
63 Correct 189 ms 23988 KB Output is correct
64 Correct 209 ms 24108 KB Output is correct
65 Correct 0 ms 340 KB Output is correct
66 Correct 46 ms 6316 KB Output is correct
67 Correct 191 ms 24084 KB Output is correct
68 Correct 183 ms 23996 KB Output is correct
69 Correct 212 ms 24056 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 352 KB Output is correct
73 Correct 45 ms 6300 KB Output is correct
74 Correct 178 ms 24036 KB Output is correct
75 Correct 198 ms 23972 KB Output is correct
76 Correct 190 ms 23976 KB Output is correct
77 Correct 209 ms 24268 KB Output is correct
78 Correct 1 ms 352 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 4 ms 876 KB Output is correct
81 Correct 88 ms 14136 KB Output is correct
82 Correct 1 ms 352 KB Output is correct
83 Correct 1 ms 348 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 61 ms 6304 KB Output is correct
86 Correct 75 ms 14156 KB Output is correct
87 Correct 70 ms 14120 KB Output is correct
88 Correct 78 ms 14124 KB Output is correct
89 Correct 85 ms 14124 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 6 ms 852 KB Output is correct
93 Correct 106 ms 14052 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 18 ms 3752 KB Output is correct
98 Correct 68 ms 14132 KB Output is correct
99 Correct 72 ms 14140 KB Output is correct
100 Correct 73 ms 14072 KB Output is correct
101 Correct 69 ms 14156 KB Output is correct
102 Correct 73 ms 14120 KB Output is correct
103 Correct 71 ms 14124 KB Output is correct
104 Correct 69 ms 14156 KB Output is correct
105 Correct 80 ms 14132 KB Output is correct