Submission #1062521

# Submission time Handle Problem Language Result Execution time Memory
1062521 2024-08-17T08:13:40 Z jerzyk Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
159 ms 27376 KB
#include <bits/stdc++.h>
#include "supertrees.h"

using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1000 + 7;
int tab[N][N], sp[N];
vector<vector<int>> answer;
int vis[N];

void L(int a, int b)
{
    answer[a - 1][b - 1] = 1;
    answer[b - 1][a - 1] = 1;
}

int construct(vector<vector<int>> xd)
{
    int n = xd.size();
    answer = xd;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
        {
            answer[i - 1][j - 1] = 0;
            tab[i][j] = xd[i - 1][j - 1];
            if(tab[i][j] == 3) return 0;
        }
    for(int i = 1; i <= n; ++i)
    {
        if(sp[i] == 0) sp[i] = i;
        for(int j = i + 1; j <= n; ++j)
        {
            if(sp[i] == sp[j] && tab[i][j] != 1) return 0;
            if(tab[i][j] != 1) continue;

            if(tab[i][j] == 1 && sp[j] == 0)
            {
                L(i, j);
                sp[j] = sp[i];
            }
            if(sp[i] != sp[j]) return 0;
        }
    }
    cerr << "xd2\n";
    for(int i = 1; i <= n; ++i)
    {
        for(int j = i + 1; j <= n; ++j)
        {
            if(sp[i] == sp[j] && tab[i][j] != 1) return 0;
            if(sp[i] == sp[j]) continue;
            if(tab[i][j] != tab[sp[i]][sp[j]]) return 0;
        }
    }
    for(int i = 1; i <= n; ++i)
    {
        if(sp[i] != i) continue;
        if(vis[i])
        {
            //cerr << "vis: " << i << " " << vis[i] << "\n";
            for(int j = i + 1; j <= n; ++j)
                if(tab[i][j] == 2 && vis[i] != vis[j] && sp[j] == j)
                    return 0;
            continue;
        }
        //cerr << "cyc " << i << "\n";
        vector<int> cur;
        cur.pb(i);
        for(int j = 1; j <= n; ++j)
        {
            if(tab[i][j] == 2 && vis[j]) return 0;
            if(sp[j] == j && tab[i][j] == 2)
                cur.pb(j);
        }
        /*cerr << "cur " << cur.size() << "\n";
        for(int j = 0; j < (int)cur.size(); ++j)
            cerr << cur[j] << " ";
        cerr << "\n";*/
        if(cur.size() == 1) continue;
        if(cur.size() == 2) return 0;

        for(int l = 0; l < (int)cur.size(); ++l)
            for(int j = l + 1; j < (int)cur.size(); ++j)
                if(tab[cur[l]][cur[j]] != 2) return 0;
        for(int j = 1; j < (int)cur.size(); ++j)
        {
            L(cur[j - 1], cur[j]);
            vis[cur[j]] = i;
        }
        L(cur.back(), cur[0]);
        cerr << "end\n";
    }
    build(answer);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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 5 ms 3424 KB Output is correct
7 Correct 113 ms 25888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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 5 ms 3424 KB Output is correct
7 Correct 113 ms 25888 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 3420 KB Output is correct
13 Correct 122 ms 26132 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 2908 KB Output is correct
17 Correct 56 ms 16148 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 37 ms 7952 KB Output is correct
21 Correct 122 ms 25936 KB Output is correct
22 Correct 115 ms 25892 KB Output is correct
23 Correct 124 ms 26132 KB Output is correct
24 Correct 125 ms 25888 KB Output is correct
25 Correct 55 ms 16212 KB Output is correct
26 Correct 51 ms 16212 KB Output is correct
27 Correct 118 ms 25940 KB Output is correct
28 Correct 117 ms 25940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 6 ms 3420 KB Output is correct
9 Correct 133 ms 27376 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 448 KB Output is correct
12 Correct 8 ms 3416 KB Output is correct
13 Correct 116 ms 27268 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 2992 KB Output is correct
17 Correct 59 ms 17428 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 30 ms 8532 KB Output is correct
22 Correct 116 ms 27216 KB Output is correct
23 Correct 125 ms 27208 KB Output is correct
24 Correct 126 ms 27220 KB Output is correct
25 Correct 59 ms 17236 KB Output is correct
26 Correct 62 ms 17500 KB Output is correct
27 Correct 116 ms 27216 KB Output is correct
28 Correct 121 ms 27216 KB Output is correct
29 Correct 54 ms 17208 KB Output is correct
# Verdict Execution time Memory 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 29 ms 7924 KB Output is correct
5 Correct 115 ms 25936 KB Output is correct
6 Correct 130 ms 26312 KB Output is correct
7 Correct 119 ms 25940 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 29 ms 7992 KB Output is correct
10 Correct 115 ms 25896 KB Output is correct
11 Correct 114 ms 25936 KB Output is correct
12 Correct 146 ms 26136 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 30 ms 7968 KB Output is correct
17 Correct 159 ms 26128 KB Output is correct
18 Correct 115 ms 25996 KB Output is correct
19 Correct 119 ms 26064 KB Output is correct
20 Correct 118 ms 25940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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 5 ms 3424 KB Output is correct
7 Correct 113 ms 25888 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 3420 KB Output is correct
13 Correct 122 ms 26132 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 2908 KB Output is correct
17 Correct 56 ms 16148 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 37 ms 7952 KB Output is correct
21 Correct 122 ms 25936 KB Output is correct
22 Correct 115 ms 25892 KB Output is correct
23 Correct 124 ms 26132 KB Output is correct
24 Correct 125 ms 25888 KB Output is correct
25 Correct 55 ms 16212 KB Output is correct
26 Correct 51 ms 16212 KB Output is correct
27 Correct 118 ms 25940 KB Output is correct
28 Correct 117 ms 25940 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 6 ms 3420 KB Output is correct
37 Correct 133 ms 27376 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 448 KB Output is correct
40 Correct 8 ms 3416 KB Output is correct
41 Correct 116 ms 27268 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 3 ms 2992 KB Output is correct
45 Correct 59 ms 17428 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 30 ms 8532 KB Output is correct
50 Correct 116 ms 27216 KB Output is correct
51 Correct 125 ms 27208 KB Output is correct
52 Correct 126 ms 27220 KB Output is correct
53 Correct 59 ms 17236 KB Output is correct
54 Correct 62 ms 17500 KB Output is correct
55 Correct 116 ms 27216 KB Output is correct
56 Correct 121 ms 27216 KB Output is correct
57 Correct 54 ms 17208 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 3164 KB Output is correct
61 Correct 59 ms 17524 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 30 ms 8592 KB Output is correct
66 Correct 54 ms 17404 KB Output is correct
67 Correct 53 ms 17232 KB Output is correct
68 Correct 54 ms 17160 KB Output is correct
69 Correct 57 ms 17200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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 5 ms 3424 KB Output is correct
7 Correct 113 ms 25888 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 3420 KB Output is correct
13 Correct 122 ms 26132 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 2908 KB Output is correct
17 Correct 56 ms 16148 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 37 ms 7952 KB Output is correct
21 Correct 122 ms 25936 KB Output is correct
22 Correct 115 ms 25892 KB Output is correct
23 Correct 124 ms 26132 KB Output is correct
24 Correct 125 ms 25888 KB Output is correct
25 Correct 55 ms 16212 KB Output is correct
26 Correct 51 ms 16212 KB Output is correct
27 Correct 118 ms 25940 KB Output is correct
28 Correct 117 ms 25940 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 6 ms 3420 KB Output is correct
37 Correct 133 ms 27376 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 448 KB Output is correct
40 Correct 8 ms 3416 KB Output is correct
41 Correct 116 ms 27268 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 3 ms 2992 KB Output is correct
45 Correct 59 ms 17428 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 30 ms 8532 KB Output is correct
50 Correct 116 ms 27216 KB Output is correct
51 Correct 125 ms 27208 KB Output is correct
52 Correct 126 ms 27220 KB Output is correct
53 Correct 59 ms 17236 KB Output is correct
54 Correct 62 ms 17500 KB Output is correct
55 Correct 116 ms 27216 KB Output is correct
56 Correct 121 ms 27216 KB Output is correct
57 Correct 54 ms 17208 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 29 ms 7924 KB Output is correct
62 Correct 115 ms 25936 KB Output is correct
63 Correct 130 ms 26312 KB Output is correct
64 Correct 119 ms 25940 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 29 ms 7992 KB Output is correct
67 Correct 115 ms 25896 KB Output is correct
68 Correct 114 ms 25936 KB Output is correct
69 Correct 146 ms 26136 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 30 ms 7968 KB Output is correct
74 Correct 159 ms 26128 KB Output is correct
75 Correct 115 ms 25996 KB Output is correct
76 Correct 119 ms 26064 KB Output is correct
77 Correct 118 ms 25940 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 3 ms 3164 KB Output is correct
81 Correct 59 ms 17524 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 1 ms 348 KB Output is correct
85 Correct 30 ms 8592 KB Output is correct
86 Correct 54 ms 17404 KB Output is correct
87 Correct 53 ms 17232 KB Output is correct
88 Correct 54 ms 17160 KB Output is correct
89 Correct 57 ms 17200 KB Output is correct
90 Correct 1 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 3 ms 860 KB Output is correct
93 Correct 52 ms 13396 KB Output is correct
94 Correct 0 ms 344 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 13 ms 3984 KB Output is correct
98 Correct 63 ms 15552 KB Output is correct
99 Correct 55 ms 15700 KB Output is correct
100 Correct 58 ms 15700 KB Output is correct
101 Correct 50 ms 15700 KB Output is correct
102 Correct 50 ms 13312 KB Output is correct
103 Correct 54 ms 13396 KB Output is correct
104 Correct 49 ms 13392 KB Output is correct
105 Correct 58 ms 13392 KB Output is correct