Submission #304724

# Submission time Handle Problem Language Result Execution time Memory
304724 2020-09-21T18:54:11 Z ocarima Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
258 ms 26360 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for(int i = (a); i <= (b); i++)

#define debugsl(y) cerr << #y << " = " << y << ", "
#define debug(x) debugsl(x) << endl


#define MAX_N 1001

vector<vector<int> > respuesta, entrada;
vector<int> linea[MAX_N]; // VECTOR PARA GUARDAR LOS NODOS DE CADA LINEA
vector<int> ciclo[MAX_N]; // NODOS EN CADA CICLO
int grupo[MAX_N], grupoCiclo[MAX_N], cicloGrupos[MAX_N][MAX_N]; // SUBGRAFO AL QUE PERTENECE CADA NODO

void puente(int a, int b){
    if (a == b) return;
    respuesta[a][b] = respuesta[b][a] = 1;
}

bool checaGrupos(int a, int b){
    bool ok = true;
    if (cicloGrupos[a][b] == 1 || a == b) return true;

    for(auto i : linea[a]){
        for(auto j : linea[b]){
            if (entrada[i][j] != 2) {
                ok = false;
                break;
            }
        }
        if (!ok) break;
    }

    if (ok) cicloGrupos[a][b] = cicloGrupos[b][a] = 1;

    return ok;
}

int construct(std::vector<std::vector<int> > p) {
	int n = p.size();
	entrada = p;
	rep(i, 0, n - 1){
	    vector<int> fila;
	    fila.resize(n);
	    respuesta.push_back(fila);
	}

    rep(i, 0, n - 1) grupo[i] = grupoCiclo[i] = i;

    rep(i, 0, n - 1){
        rep(j, i + 1, n - 1){
            if (p[i][j] == 3) return 0;
            if (p[i][j] == 0 && grupo[i] == grupo[j]) return 0;
            else if(p[i][j] == 1 && grupo[i] == i && grupo[j] == j){
                linea[i].push_back(j);
                grupo[j] = i;
            }
            else if (p[i][j] == 1 && grupo[i] != grupo[j]) return 0;
        }
        linea[i].push_back(i);
    }

    rep(i, 0, n - 1){
        rep(j, i + 1, n - 1){
            if (p[i][j] == 0 && grupoCiclo[grupo[i]] == grupoCiclo[grupo[j]]) return 0;
            else if(p[i][j] == 2 && grupoCiclo[grupo[i]] != grupoCiclo[grupo[j]]){
                if (grupoCiclo[grupo[i]] == grupo[i] && grupoCiclo[grupo[j]] == grupo[j]){
                    ciclo[grupo[i]].push_back(grupo[j]);
                    grupoCiclo[grupo[j]] = grupo[i];
                }
                else return 0;
            }
        }
    }

	rep(i, 0, n - 1)
	    for(auto nodo : linea[i])
            puente(i, nodo);

    rep(i, 0, n - 1){
	    if (ciclo[i].size() == 1) return 0; // NO PUEDE HABER UN CICLO DE SOLO 2 NODOS
	    if (ciclo[i].size() > 0){
            rep(j, 0, ciclo[i].size() - 1){
                if (j > 0) puente(ciclo[i][j], ciclo[i][j - 1]);
                if (j < ciclo[i].size() - 1) puente(ciclo[i][j], ciclo[i][j + 1]);
            }
            puente(i, ciclo[i][0]);
            puente(i, ciclo[i][ciclo[i].size() - 1]);
	    }
	}

	build(respuesta);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:7:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define rep(i, a, b) for(int i = (a); i <= (b); i++)
      |                                         ^
supertrees.cpp:88:13: note: in expansion of macro 'rep'
   88 |             rep(j, 0, ciclo[i].size() - 1){
      |             ^~~
supertrees.cpp:90:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |                 if (j < ciclo[i].size() - 1) puente(ciclo[i][j], ciclo[i][j + 1]);
      |                     ~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 240 ms 26104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 240 ms 26104 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1440 KB Output is correct
13 Correct 245 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 107 ms 16144 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 61 ms 6904 KB Output is correct
21 Correct 247 ms 26104 KB Output is correct
22 Correct 241 ms 26232 KB Output is correct
23 Correct 249 ms 26104 KB Output is correct
24 Correct 242 ms 26104 KB Output is correct
25 Correct 104 ms 16248 KB Output is correct
26 Correct 101 ms 16120 KB Output is correct
27 Correct 246 ms 26104 KB Output is correct
28 Correct 241 ms 26232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 416 KB Output is correct
8 Correct 10 ms 1408 KB Output is correct
9 Correct 238 ms 26236 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 247 ms 26124 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 111 ms 16268 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 60 ms 6904 KB Output is correct
22 Correct 242 ms 26104 KB Output is correct
23 Correct 248 ms 26232 KB Output is correct
24 Correct 245 ms 26360 KB Output is correct
25 Correct 104 ms 16380 KB Output is correct
26 Correct 107 ms 16308 KB Output is correct
27 Correct 240 ms 26232 KB Output is correct
28 Correct 247 ms 26108 KB Output is correct
29 Correct 102 ms 16248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 60 ms 6904 KB Output is correct
5 Correct 246 ms 26232 KB Output is correct
6 Correct 239 ms 26104 KB Output is correct
7 Correct 249 ms 26124 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 61 ms 6904 KB Output is correct
10 Correct 247 ms 26360 KB Output is correct
11 Correct 245 ms 26232 KB Output is correct
12 Correct 258 ms 26104 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 61 ms 6904 KB Output is correct
17 Correct 240 ms 26104 KB Output is correct
18 Correct 241 ms 26060 KB Output is correct
19 Correct 239 ms 26104 KB Output is correct
20 Correct 243 ms 26104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 240 ms 26104 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1440 KB Output is correct
13 Correct 245 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 107 ms 16144 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 61 ms 6904 KB Output is correct
21 Correct 247 ms 26104 KB Output is correct
22 Correct 241 ms 26232 KB Output is correct
23 Correct 249 ms 26104 KB Output is correct
24 Correct 242 ms 26104 KB Output is correct
25 Correct 104 ms 16248 KB Output is correct
26 Correct 101 ms 16120 KB Output is correct
27 Correct 246 ms 26104 KB Output is correct
28 Correct 241 ms 26232 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 416 KB Output is correct
36 Correct 10 ms 1408 KB Output is correct
37 Correct 238 ms 26236 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 10 ms 1408 KB Output is correct
41 Correct 247 ms 26124 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 5 ms 1024 KB Output is correct
45 Correct 111 ms 16268 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 60 ms 6904 KB Output is correct
50 Correct 242 ms 26104 KB Output is correct
51 Correct 248 ms 26232 KB Output is correct
52 Correct 245 ms 26360 KB Output is correct
53 Correct 104 ms 16380 KB Output is correct
54 Correct 107 ms 16308 KB Output is correct
55 Correct 240 ms 26232 KB Output is correct
56 Correct 247 ms 26108 KB Output is correct
57 Correct 102 ms 16248 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 5 ms 1024 KB Output is correct
61 Correct 106 ms 16136 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 436 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 61 ms 6876 KB Output is correct
66 Correct 102 ms 16248 KB Output is correct
67 Correct 103 ms 16140 KB Output is correct
68 Correct 105 ms 16376 KB Output is correct
69 Correct 104 ms 16248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 10 ms 1280 KB Output is correct
7 Correct 240 ms 26104 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1440 KB Output is correct
13 Correct 245 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 107 ms 16144 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 61 ms 6904 KB Output is correct
21 Correct 247 ms 26104 KB Output is correct
22 Correct 241 ms 26232 KB Output is correct
23 Correct 249 ms 26104 KB Output is correct
24 Correct 242 ms 26104 KB Output is correct
25 Correct 104 ms 16248 KB Output is correct
26 Correct 101 ms 16120 KB Output is correct
27 Correct 246 ms 26104 KB Output is correct
28 Correct 241 ms 26232 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 416 KB Output is correct
36 Correct 10 ms 1408 KB Output is correct
37 Correct 238 ms 26236 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 10 ms 1408 KB Output is correct
41 Correct 247 ms 26124 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 5 ms 1024 KB Output is correct
45 Correct 111 ms 16268 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 60 ms 6904 KB Output is correct
50 Correct 242 ms 26104 KB Output is correct
51 Correct 248 ms 26232 KB Output is correct
52 Correct 245 ms 26360 KB Output is correct
53 Correct 104 ms 16380 KB Output is correct
54 Correct 107 ms 16308 KB Output is correct
55 Correct 240 ms 26232 KB Output is correct
56 Correct 247 ms 26108 KB Output is correct
57 Correct 102 ms 16248 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 0 ms 384 KB Output is correct
60 Correct 0 ms 384 KB Output is correct
61 Correct 60 ms 6904 KB Output is correct
62 Correct 246 ms 26232 KB Output is correct
63 Correct 239 ms 26104 KB Output is correct
64 Correct 249 ms 26124 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 61 ms 6904 KB Output is correct
67 Correct 247 ms 26360 KB Output is correct
68 Correct 245 ms 26232 KB Output is correct
69 Correct 258 ms 26104 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 61 ms 6904 KB Output is correct
74 Correct 240 ms 26104 KB Output is correct
75 Correct 241 ms 26060 KB Output is correct
76 Correct 239 ms 26104 KB Output is correct
77 Correct 243 ms 26104 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 0 ms 384 KB Output is correct
80 Correct 5 ms 1024 KB Output is correct
81 Correct 106 ms 16136 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 436 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 61 ms 6876 KB Output is correct
86 Correct 102 ms 16248 KB Output is correct
87 Correct 103 ms 16140 KB Output is correct
88 Correct 105 ms 16376 KB Output is correct
89 Correct 104 ms 16248 KB Output is correct
90 Correct 0 ms 384 KB Output is correct
91 Correct 0 ms 384 KB Output is correct
92 Correct 5 ms 1024 KB Output is correct
93 Correct 105 ms 16120 KB Output is correct
94 Correct 0 ms 384 KB Output is correct
95 Correct 0 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 26 ms 4352 KB Output is correct
98 Correct 101 ms 16136 KB Output is correct
99 Correct 101 ms 16120 KB Output is correct
100 Correct 100 ms 16120 KB Output is correct
101 Correct 103 ms 16144 KB Output is correct
102 Correct 102 ms 16120 KB Output is correct
103 Correct 102 ms 16140 KB Output is correct
104 Correct 104 ms 16120 KB Output is correct
105 Correct 111 ms 16248 KB Output is correct