Submission #1007442

# Submission time Handle Problem Language Result Execution time Memory
1007442 2024-06-25T00:53:41 Z u_suck_o Connecting Supertrees (IOI20_supertrees) C++17
96 / 100
114 ms 22316 KB
#include "supertrees.h"
#include "bits/stdc++.h"
#define MAXN 1005

using namespace std;

int N;
int sizes[MAXN], par[MAXN];
vector<int> comps[MAXN], comps1[MAXN];
vector<vector<int>> answer;

int find(int u) {
    if (u != par[u])
        par[u] = find(par[u]);
    return par[u];
}

void join(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) return;
    //answer[u][v] = 1;
    //answer[v][u] = 1;
    if (sizes[u] > sizes[v]) {
        par[v] = u;
        sizes[u] += sizes[v];
    } else {
        par[u] = v;
        sizes[v] += sizes[u];
    }
}

void reset_dsu() {
    for (int i = 0; i < N; i++) {
        par[i] = i;
        sizes[i] = 1;
    }
}
int construct(vector<vector<int>> p) {
    N = p.size();
    answer = vector<vector<int>>(N, vector<int>(N, 0));
    
    //run dsu
    reset_dsu();
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            if (p[i][j])
                join(i, j);
        }
    }
    //build components
    for (int i = 0; i < N; i++)
        comps[find(i)].push_back(i);
    
    //run dsu again to find comps of 1
    reset_dsu();
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < comps[i].size(); j++) {
            for (int k = j+1; k < comps[i].size(); k++) {
                int x = comps[i][j], y = comps[i][k];
                if (p[x][y] == 0) return 0;
                if (p[x][y] == 1) join(x, y);
            }
        }
    }
    vector<int> reps;
    for (int i = 0; i < N; i++)
        comps1[find(i)].push_back(i);
    
    //check validity
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            if (find(i) == find(j) && p[i][j] != 1)
                return 0;
        }
    }
    
    //build paths
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < ((int) comps1[i].size())-1; j++) {
            answer[comps1[i][j]][comps1[i][j+1]] = 1;
            answer[comps1[i][j+1]][comps1[i][j]] = 1;
        }
    }
    
    //build rings
    for (int i = 0; i < N; i++) {
        vector<int> reps;
        for (int j : comps[i]) {
            if (j == find(j))
                reps.push_back(j);
        }
        
        if (reps.size() == 2)
            return 0;
        if (reps.size() <= 1) continue;
        for (int j = 0; j < reps.size() - 1; j++) {
            answer[reps[j]][reps[j+1]] = 1;
            answer[reps[j+1]][reps[j]] = 1;
        }
        answer[reps[0]][reps[reps.size()-1]] = 1;
        answer[reps[reps.size()-1]][reps[0]] = 1;
    }
    build(answer);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:58:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for (int j = 0; j < comps[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:59:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             for (int k = j+1; k < comps[i].size(); k++) {
      |                               ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:97:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |         for (int j = 0; j < reps.size() - 1; j++) {
      |                         ~~^~~~~~~~~~~~~~~~~
# 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 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 4 ms 1308 KB Output is correct
7 Correct 100 ms 22136 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 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 4 ms 1308 KB Output is correct
7 Correct 100 ms 22136 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 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 5 ms 1372 KB Output is correct
13 Correct 109 ms 22100 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 53 ms 12096 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 25 ms 5892 KB Output is correct
21 Correct 105 ms 22092 KB Output is correct
22 Correct 92 ms 22100 KB Output is correct
23 Correct 106 ms 22096 KB Output is correct
24 Correct 97 ms 22096 KB Output is correct
25 Correct 43 ms 12112 KB Output is correct
26 Correct 44 ms 12116 KB Output is correct
27 Correct 106 ms 22316 KB Output is correct
28 Correct 102 ms 22096 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 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 1372 KB Output is correct
9 Correct 108 ms 22096 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 101 ms 22252 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 908 KB Output is correct
17 Correct 53 ms 12124 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 28 ms 5820 KB Output is correct
22 Correct 101 ms 22104 KB Output is correct
23 Correct 101 ms 22096 KB Output is correct
24 Correct 103 ms 22076 KB Output is correct
25 Correct 43 ms 12368 KB Output is correct
26 Correct 43 ms 12104 KB Output is correct
27 Correct 102 ms 22104 KB Output is correct
28 Correct 113 ms 22092 KB Output is correct
29 Correct 44 ms 12368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 30 ms 5868 KB Output is correct
5 Correct 107 ms 22168 KB Output is correct
6 Correct 100 ms 22100 KB Output is correct
7 Correct 104 ms 22056 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 31 ms 5956 KB Output is correct
10 Correct 109 ms 22088 KB Output is correct
11 Correct 106 ms 22096 KB Output is correct
12 Correct 108 ms 22100 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 27 ms 5820 KB Output is correct
17 Correct 104 ms 22096 KB Output is correct
18 Correct 114 ms 22028 KB Output is correct
19 Correct 109 ms 22072 KB Output is correct
20 Correct 108 ms 22100 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 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 4 ms 1308 KB Output is correct
7 Correct 100 ms 22136 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 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 5 ms 1372 KB Output is correct
13 Correct 109 ms 22100 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 53 ms 12096 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 25 ms 5892 KB Output is correct
21 Correct 105 ms 22092 KB Output is correct
22 Correct 92 ms 22100 KB Output is correct
23 Correct 106 ms 22096 KB Output is correct
24 Correct 97 ms 22096 KB Output is correct
25 Correct 43 ms 12112 KB Output is correct
26 Correct 44 ms 12116 KB Output is correct
27 Correct 106 ms 22316 KB Output is correct
28 Correct 102 ms 22096 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 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 1372 KB Output is correct
37 Correct 108 ms 22096 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 1372 KB Output is correct
41 Correct 101 ms 22252 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 908 KB Output is correct
45 Correct 53 ms 12124 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 28 ms 5820 KB Output is correct
50 Correct 101 ms 22104 KB Output is correct
51 Correct 101 ms 22096 KB Output is correct
52 Correct 103 ms 22076 KB Output is correct
53 Correct 43 ms 12368 KB Output is correct
54 Correct 43 ms 12104 KB Output is correct
55 Correct 102 ms 22104 KB Output is correct
56 Correct 113 ms 22092 KB Output is correct
57 Correct 44 ms 12368 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 860 KB Output is correct
61 Correct 62 ms 12104 KB Output is correct
62 Correct 0 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 28 ms 5980 KB Output is correct
66 Correct 48 ms 12112 KB Output is correct
67 Correct 43 ms 12108 KB Output is correct
68 Correct 45 ms 12116 KB Output is correct
69 Correct 42 ms 12368 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 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 4 ms 1308 KB Output is correct
7 Correct 100 ms 22136 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 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 5 ms 1372 KB Output is correct
13 Correct 109 ms 22100 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 53 ms 12096 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 25 ms 5892 KB Output is correct
21 Correct 105 ms 22092 KB Output is correct
22 Correct 92 ms 22100 KB Output is correct
23 Correct 106 ms 22096 KB Output is correct
24 Correct 97 ms 22096 KB Output is correct
25 Correct 43 ms 12112 KB Output is correct
26 Correct 44 ms 12116 KB Output is correct
27 Correct 106 ms 22316 KB Output is correct
28 Correct 102 ms 22096 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 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 1372 KB Output is correct
37 Correct 108 ms 22096 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 1372 KB Output is correct
41 Correct 101 ms 22252 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 908 KB Output is correct
45 Correct 53 ms 12124 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 28 ms 5820 KB Output is correct
50 Correct 101 ms 22104 KB Output is correct
51 Correct 101 ms 22096 KB Output is correct
52 Correct 103 ms 22076 KB Output is correct
53 Correct 43 ms 12368 KB Output is correct
54 Correct 43 ms 12104 KB Output is correct
55 Correct 102 ms 22104 KB Output is correct
56 Correct 113 ms 22092 KB Output is correct
57 Correct 44 ms 12368 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 30 ms 5868 KB Output is correct
62 Correct 107 ms 22168 KB Output is correct
63 Correct 100 ms 22100 KB Output is correct
64 Correct 104 ms 22056 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 31 ms 5956 KB Output is correct
67 Correct 109 ms 22088 KB Output is correct
68 Correct 106 ms 22096 KB Output is correct
69 Correct 108 ms 22100 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 27 ms 5820 KB Output is correct
74 Correct 104 ms 22096 KB Output is correct
75 Correct 114 ms 22028 KB Output is correct
76 Correct 109 ms 22072 KB Output is correct
77 Correct 108 ms 22100 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 3 ms 860 KB Output is correct
81 Correct 62 ms 12104 KB Output is correct
82 Correct 0 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 28 ms 5980 KB Output is correct
86 Correct 48 ms 12112 KB Output is correct
87 Correct 43 ms 12108 KB Output is correct
88 Correct 45 ms 12116 KB Output is correct
89 Correct 42 ms 12368 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 2 ms 860 KB Output is correct
93 Correct 47 ms 12116 KB Output is correct
94 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -