Submission #319737

# Submission time Handle Problem Language Result Execution time Memory
319737 2020-11-06T10:23:46 Z alextodoran Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
265 ms 28132 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>
#include "supertrees.h"

using namespace std;

typedef long long ll;

const int N_MAX = 1002;

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

int n;

vector <int> edges[N_MAX];

bool visited[N_MAX];

vector <int> aux;

void dfs (int u)
{
    visited[u] = true;
    aux.push_back(u);
    for(int v : edges[u])
        if(visited[v] == false)
            dfs(v);
}

bool chainRoot[N_MAX];

int chainIndex[N_MAX];
int cycleIndex[N_MAX];
int root[N_MAX];

int construct (vector <vector <int> > p)
{
    n = p.size();
    vector <vector <int> > answer;
    answer.resize(n);
    for(int i = 0; i < n; i++)
        answer[i].resize(n);
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            answer[i][j] = false;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            if(p[i][j] == 3)
                return false;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            if(p[i][j] == 1)
                edges[i].push_back(j);
    int curr;
    curr = 0;
    for(int i = 0; i < n; i++)
        if(visited[i] == false)
        {
            dfs(i);
            chainRoot[i] = true;
            curr++;
            for(int j = 0; j < (int)aux.size(); j++)
                chainIndex[aux[j]] = curr;
            root[curr] = i;
            for(int j = 1; j < (int)aux.size(); j++)
                answer[aux[j - 1]][aux[j]] = answer[aux[j]][aux[j - 1]] = true;
            aux.clear();
        }
    for(int i = 0; i < n; i++)
    {
        edges[i].clear();
        visited[i] = false;
    }
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            if(p[i][j] == 2)
                edges[i].push_back(j);
    for(int i = 0; i < n; i++)
        if(chainRoot[i] == false)
            visited[i] = true;
    curr = 0;
    for(int i = 0; i < n; i++)
        if(visited[i] == false)
        {
            dfs(i);
            chainRoot[i] = true;
            curr++;
            if((int)aux.size() == 2)
                return false;
            for(int j = 0; j < (int)aux.size(); j++)
                cycleIndex[aux[j]] = curr;
            for(int j = 0; j < (int)aux.size(); j++)
            {
                int j1 = j - 1;
                if(j == 0)
                    j1 += (int)aux.size();
                if(j != j1)
                    answer[aux[j1]][aux[j]] = answer[aux[j]][aux[j1]] = true;
            }
            aux.clear();
        }
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            if(i != j)
            {
                int cnt = 0;
                if(cycleIndex[root[chainIndex[i]]] == cycleIndex[root[chainIndex[j]]] && chainIndex[i] != chainIndex[j])
                    cnt = 2;
                else if(chainIndex[i] == chainIndex[j])
                    cnt = 1;
                else
                    cnt = 0;
                if(cnt != p[i][j])
                    return false;
            }
    build(answer);
    return true;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 396 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1516 KB Output is correct
7 Correct 254 ms 26340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 396 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1516 KB Output is correct
7 Correct 254 ms 26340 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 248 ms 22116 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1004 KB Output is correct
17 Correct 125 ms 14820 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 63 ms 5864 KB Output is correct
21 Correct 253 ms 22628 KB Output is correct
22 Correct 245 ms 22116 KB Output is correct
23 Correct 259 ms 24164 KB Output is correct
24 Correct 251 ms 22264 KB Output is correct
25 Correct 112 ms 12772 KB Output is correct
26 Correct 108 ms 12392 KB Output is correct
27 Correct 265 ms 25316 KB Output is correct
28 Correct 250 ms 22352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 11 ms 1388 KB Output is correct
9 Correct 247 ms 24164 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 12 ms 1516 KB Output is correct
13 Correct 257 ms 28132 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1004 KB Output is correct
17 Correct 127 ms 16612 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 68 ms 6376 KB Output is correct
22 Correct 260 ms 24804 KB Output is correct
23 Correct 255 ms 24164 KB Output is correct
24 Correct 258 ms 27108 KB Output is correct
25 Correct 112 ms 14180 KB Output is correct
26 Correct 114 ms 14820 KB Output is correct
27 Correct 249 ms 24164 KB Output is correct
28 Correct 259 ms 26084 KB Output is correct
29 Correct 109 ms 14180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 67 ms 5860 KB Output is correct
5 Correct 252 ms 22632 KB Output is correct
6 Correct 247 ms 22116 KB Output is correct
7 Correct 263 ms 24164 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 68 ms 5856 KB Output is correct
10 Correct 251 ms 22756 KB Output is correct
11 Correct 254 ms 22116 KB Output is correct
12 Correct 259 ms 25316 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 66 ms 5860 KB Output is correct
17 Correct 253 ms 22628 KB Output is correct
18 Correct 256 ms 22756 KB Output is correct
19 Correct 253 ms 22372 KB Output is correct
20 Correct 247 ms 22244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 396 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1516 KB Output is correct
7 Correct 254 ms 26340 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 248 ms 22116 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1004 KB Output is correct
17 Correct 125 ms 14820 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 63 ms 5864 KB Output is correct
21 Correct 253 ms 22628 KB Output is correct
22 Correct 245 ms 22116 KB Output is correct
23 Correct 259 ms 24164 KB Output is correct
24 Correct 251 ms 22264 KB Output is correct
25 Correct 112 ms 12772 KB Output is correct
26 Correct 108 ms 12392 KB Output is correct
27 Correct 265 ms 25316 KB Output is correct
28 Correct 250 ms 22352 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 11 ms 1388 KB Output is correct
37 Correct 247 ms 24164 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 12 ms 1516 KB Output is correct
41 Correct 257 ms 28132 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 1004 KB Output is correct
45 Correct 127 ms 16612 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 68 ms 6376 KB Output is correct
50 Correct 260 ms 24804 KB Output is correct
51 Correct 255 ms 24164 KB Output is correct
52 Correct 258 ms 27108 KB Output is correct
53 Correct 112 ms 14180 KB Output is correct
54 Correct 114 ms 14820 KB Output is correct
55 Correct 249 ms 24164 KB Output is correct
56 Correct 259 ms 26084 KB Output is correct
57 Correct 109 ms 14180 KB Output is correct
58 Correct 1 ms 396 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 6 ms 1004 KB Output is correct
61 Correct 126 ms 16252 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 63 ms 6372 KB Output is correct
66 Correct 115 ms 14820 KB Output is correct
67 Correct 116 ms 14692 KB Output is correct
68 Correct 112 ms 14436 KB Output is correct
69 Correct 110 ms 14308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 396 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1516 KB Output is correct
7 Correct 254 ms 26340 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 1260 KB Output is correct
13 Correct 248 ms 22116 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1004 KB Output is correct
17 Correct 125 ms 14820 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 63 ms 5864 KB Output is correct
21 Correct 253 ms 22628 KB Output is correct
22 Correct 245 ms 22116 KB Output is correct
23 Correct 259 ms 24164 KB Output is correct
24 Correct 251 ms 22264 KB Output is correct
25 Correct 112 ms 12772 KB Output is correct
26 Correct 108 ms 12392 KB Output is correct
27 Correct 265 ms 25316 KB Output is correct
28 Correct 250 ms 22352 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 11 ms 1388 KB Output is correct
37 Correct 247 ms 24164 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 12 ms 1516 KB Output is correct
41 Correct 257 ms 28132 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 6 ms 1004 KB Output is correct
45 Correct 127 ms 16612 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 68 ms 6376 KB Output is correct
50 Correct 260 ms 24804 KB Output is correct
51 Correct 255 ms 24164 KB Output is correct
52 Correct 258 ms 27108 KB Output is correct
53 Correct 112 ms 14180 KB Output is correct
54 Correct 114 ms 14820 KB Output is correct
55 Correct 249 ms 24164 KB Output is correct
56 Correct 259 ms 26084 KB Output is correct
57 Correct 109 ms 14180 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 67 ms 5860 KB Output is correct
62 Correct 252 ms 22632 KB Output is correct
63 Correct 247 ms 22116 KB Output is correct
64 Correct 263 ms 24164 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 68 ms 5856 KB Output is correct
67 Correct 251 ms 22756 KB Output is correct
68 Correct 254 ms 22116 KB Output is correct
69 Correct 259 ms 25316 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 66 ms 5860 KB Output is correct
74 Correct 253 ms 22628 KB Output is correct
75 Correct 256 ms 22756 KB Output is correct
76 Correct 253 ms 22372 KB Output is correct
77 Correct 247 ms 22244 KB Output is correct
78 Correct 1 ms 396 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 6 ms 1004 KB Output is correct
81 Correct 126 ms 16252 KB Output is correct
82 Correct 1 ms 364 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 63 ms 6372 KB Output is correct
86 Correct 115 ms 14820 KB Output is correct
87 Correct 116 ms 14692 KB Output is correct
88 Correct 112 ms 14436 KB Output is correct
89 Correct 110 ms 14308 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 5 ms 876 KB Output is correct
93 Correct 109 ms 14184 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 28 ms 3948 KB Output is correct
98 Correct 107 ms 14180 KB Output is correct
99 Correct 107 ms 14308 KB Output is correct
100 Correct 106 ms 14308 KB Output is correct
101 Correct 103 ms 14180 KB Output is correct
102 Correct 110 ms 14308 KB Output is correct
103 Correct 101 ms 14180 KB Output is correct
104 Correct 104 ms 14308 KB Output is correct
105 Correct 111 ms 14312 KB Output is correct