Submission #963849

# Submission time Handle Problem Language Result Execution time Memory
963849 2024-04-15T19:50:16 Z nguyentunglam Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
178 ms 24396 KB
#include "supertrees.h"
#ifdef ngu
#include "grader.cpp"
#endif // ngu
#include <vector>
#include<bits/stdc++.h>
using namespace std;


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

  auto valid = [&] (vector<int> a, vector<int> b, int c) {
    for(int &j : a) for(int &k : b) if (p[j][k] != c) return false;
    return true;
  };

	vector<int> vis(n), arr;

  auto dfs = [&] (auto self, int u) -> void {
    vis[u] = 1;
    arr.push_back(u);
    for(int v = 0; v < n; v++) if (!vis[v] && p[u][v] == 1) self(self, v);
  };

	std::vector<std::vector<int>> answer(n, vector<int> (n));

  auto add = [&] (int u, int v) {
    answer[u][v] = answer[v][u] = 1;
  };

  vector<vector<int> > connected;

  for(int i = 0; i < n; i++) if (!vis[i]) {
    arr.clear();
    dfs(dfs, i);
    if (!valid(arr, arr, 1)) return 0;
    connected.push_back(arr);
    for(int j = 1; j < arr.size(); j++) {
      answer[arr[j]][arr[j - 1]] = answer[arr[j - 1]][arr[j]] = 1;
    }
  }

  for(int i = 0; i < n; i++) vis[i] = 0;

  for(int i = 0; i < connected.size(); i++) if (!vis[i]) {
    vis[i] = 1;
    vector<int> zip, g;
    g.push_back(i);
    for(auto &k : connected[i]) zip.push_back(k);
    for(int j = 0; j < connected.size(); j++) if (j != i && p[connected[i][0]][connected[j][0]] == 2) {
      if (vis[j]) return 0;
      vis[j] = 1;
      if (!valid(zip, connected[j], 2)) return 0;
      for(auto &k : connected[j]) zip.push_back(k);
      g.push_back(j);
    }
    if (g.size() == 1) continue;
    if (g.size() < 3) return 0;
//    for(int &j : g) cout << j << " "; cout << endl;
    for(int i = 1; i < g.size(); i++) {
      add(connected[g[i]][0], connected[g[i - 1]][0]);
    }
    add(connected[g[0]][0], connected[g.back()][0]);
  }

  build(answer);

	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int j = 1; j < arr.size(); j++) {
      |                    ~~^~~~~~~~~~~~
supertrees.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for(int i = 0; i < connected.size(); i++) if (!vis[i]) {
      |                  ~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int j = 0; j < connected.size(); j++) if (j != i && p[connected[i][0]][connected[j][0]] == 2) {
      |                    ~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:61:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i = 1; i < g.size(); i++) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 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 7 ms 1116 KB Output is correct
7 Correct 155 ms 22052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 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 7 ms 1116 KB Output is correct
7 Correct 155 ms 22052 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 1112 KB Output is correct
13 Correct 157 ms 22096 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 852 KB Output is correct
17 Correct 67 ms 12296 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 42 ms 5876 KB Output is correct
21 Correct 155 ms 22100 KB Output is correct
22 Correct 154 ms 22096 KB Output is correct
23 Correct 172 ms 21988 KB Output is correct
24 Correct 163 ms 22020 KB Output is correct
25 Correct 78 ms 12040 KB Output is correct
26 Correct 63 ms 12040 KB Output is correct
27 Correct 164 ms 22096 KB Output is correct
28 Correct 177 ms 22024 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 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 9 ms 1116 KB Output is correct
9 Correct 157 ms 22096 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 1220 KB Output is correct
13 Correct 157 ms 24396 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 956 KB Output is correct
17 Correct 70 ms 14160 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 40 ms 6272 KB Output is correct
22 Correct 166 ms 24176 KB Output is correct
23 Correct 165 ms 24188 KB Output is correct
24 Correct 160 ms 24188 KB Output is correct
25 Correct 66 ms 14164 KB Output is correct
26 Incorrect 166 ms 23988 KB Answer gives possible 1 while actual possible 0
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 47 ms 5768 KB Output is correct
5 Correct 169 ms 22148 KB Output is correct
6 Correct 155 ms 21976 KB Output is correct
7 Correct 163 ms 22164 KB Output is correct
8 Correct 1 ms 544 KB Output is correct
9 Correct 39 ms 6400 KB Output is correct
10 Correct 155 ms 24144 KB Output is correct
11 Correct 160 ms 24132 KB Output is correct
12 Correct 178 ms 24180 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 39 ms 6228 KB Output is correct
17 Correct 156 ms 24172 KB Output is correct
18 Correct 157 ms 23948 KB Output is correct
19 Correct 161 ms 24060 KB Output is correct
20 Correct 159 ms 24144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 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 7 ms 1116 KB Output is correct
7 Correct 155 ms 22052 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 1112 KB Output is correct
13 Correct 157 ms 22096 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 852 KB Output is correct
17 Correct 67 ms 12296 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 42 ms 5876 KB Output is correct
21 Correct 155 ms 22100 KB Output is correct
22 Correct 154 ms 22096 KB Output is correct
23 Correct 172 ms 21988 KB Output is correct
24 Correct 163 ms 22020 KB Output is correct
25 Correct 78 ms 12040 KB Output is correct
26 Correct 63 ms 12040 KB Output is correct
27 Correct 164 ms 22096 KB Output is correct
28 Correct 177 ms 22024 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 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 9 ms 1116 KB Output is correct
37 Correct 157 ms 22096 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 7 ms 1220 KB Output is correct
41 Correct 157 ms 24396 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 3 ms 956 KB Output is correct
45 Correct 70 ms 14160 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 436 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 40 ms 6272 KB Output is correct
50 Correct 166 ms 24176 KB Output is correct
51 Correct 165 ms 24188 KB Output is correct
52 Correct 160 ms 24188 KB Output is correct
53 Correct 66 ms 14164 KB Output is correct
54 Incorrect 166 ms 23988 KB Answer gives possible 1 while actual possible 0
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 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 7 ms 1116 KB Output is correct
7 Correct 155 ms 22052 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 1112 KB Output is correct
13 Correct 157 ms 22096 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 852 KB Output is correct
17 Correct 67 ms 12296 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 42 ms 5876 KB Output is correct
21 Correct 155 ms 22100 KB Output is correct
22 Correct 154 ms 22096 KB Output is correct
23 Correct 172 ms 21988 KB Output is correct
24 Correct 163 ms 22020 KB Output is correct
25 Correct 78 ms 12040 KB Output is correct
26 Correct 63 ms 12040 KB Output is correct
27 Correct 164 ms 22096 KB Output is correct
28 Correct 177 ms 22024 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 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 9 ms 1116 KB Output is correct
37 Correct 157 ms 22096 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 7 ms 1220 KB Output is correct
41 Correct 157 ms 24396 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 3 ms 956 KB Output is correct
45 Correct 70 ms 14160 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 436 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 40 ms 6272 KB Output is correct
50 Correct 166 ms 24176 KB Output is correct
51 Correct 165 ms 24188 KB Output is correct
52 Correct 160 ms 24188 KB Output is correct
53 Correct 66 ms 14164 KB Output is correct
54 Incorrect 166 ms 23988 KB Answer gives possible 1 while actual possible 0
55 Halted 0 ms 0 KB -