Submission #963850

# Submission time Handle Problem Language Result Execution time Memory
963850 2024-04-15T19:56:20 Z nguyentunglam Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
169 ms 22276 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(auto &arr : connected) {
    for(auto &j : arr) for(int k = 0; k < n; k++) if (p[j][k] != p[arr[0]][k]) return 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:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for(int i = 0; i < connected.size(); i++) if (!vis[i]) {
      |                  ~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int j = 0; j < connected.size(); j++) if (j != i && p[connected[i][0]][connected[j][0]] == 2) {
      |                    ~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(int i = 1; i < g.size(); i++) {
      |                    ~~^~~~~~~~~~
# 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 6 ms 1116 KB Output is correct
7 Correct 155 ms 22124 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 6 ms 1116 KB Output is correct
7 Correct 155 ms 22124 KB Output is correct
8 Correct 0 ms 344 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 7 ms 1108 KB Output is correct
13 Correct 151 ms 22020 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 68 ms 12372 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 38 ms 5724 KB Output is correct
21 Correct 162 ms 21972 KB Output is correct
22 Correct 163 ms 22164 KB Output is correct
23 Correct 153 ms 22076 KB Output is correct
24 Correct 152 ms 22116 KB Output is correct
25 Correct 63 ms 12056 KB Output is correct
26 Correct 60 ms 12056 KB Output is correct
27 Correct 159 ms 22128 KB Output is correct
28 Correct 151 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 344 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 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 8 ms 1116 KB Output is correct
9 Correct 159 ms 22028 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 153 ms 22264 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 860 KB Output is correct
17 Correct 68 ms 12256 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 37 ms 5744 KB Output is correct
22 Correct 158 ms 22036 KB Output is correct
23 Correct 151 ms 22024 KB Output is correct
24 Correct 161 ms 22276 KB Output is correct
25 Correct 68 ms 12116 KB Output is correct
26 Incorrect 151 ms 22104 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 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 38 ms 5792 KB Output is correct
5 Correct 149 ms 22200 KB Output is correct
6 Correct 160 ms 22176 KB Output is correct
7 Correct 159 ms 22020 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 38 ms 5680 KB Output is correct
10 Correct 156 ms 22032 KB Output is correct
11 Correct 159 ms 22172 KB Output is correct
12 Correct 169 ms 22100 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 344 KB Output is correct
16 Correct 38 ms 5780 KB Output is correct
17 Correct 157 ms 22204 KB Output is correct
18 Correct 157 ms 22044 KB Output is correct
19 Correct 158 ms 22036 KB Output is correct
20 Correct 154 ms 22040 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 6 ms 1116 KB Output is correct
7 Correct 155 ms 22124 KB Output is correct
8 Correct 0 ms 344 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 7 ms 1108 KB Output is correct
13 Correct 151 ms 22020 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 68 ms 12372 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 38 ms 5724 KB Output is correct
21 Correct 162 ms 21972 KB Output is correct
22 Correct 163 ms 22164 KB Output is correct
23 Correct 153 ms 22076 KB Output is correct
24 Correct 152 ms 22116 KB Output is correct
25 Correct 63 ms 12056 KB Output is correct
26 Correct 60 ms 12056 KB Output is correct
27 Correct 159 ms 22128 KB Output is correct
28 Correct 151 ms 22096 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 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 1 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 8 ms 1116 KB Output is correct
37 Correct 159 ms 22028 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 6 ms 1116 KB Output is correct
41 Correct 153 ms 22264 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 68 ms 12256 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 37 ms 5744 KB Output is correct
50 Correct 158 ms 22036 KB Output is correct
51 Correct 151 ms 22024 KB Output is correct
52 Correct 161 ms 22276 KB Output is correct
53 Correct 68 ms 12116 KB Output is correct
54 Incorrect 151 ms 22104 KB Answer gives possible 1 while actual possible 0
55 Halted 0 ms 0 KB -
# 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 6 ms 1116 KB Output is correct
7 Correct 155 ms 22124 KB Output is correct
8 Correct 0 ms 344 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 7 ms 1108 KB Output is correct
13 Correct 151 ms 22020 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 68 ms 12372 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 38 ms 5724 KB Output is correct
21 Correct 162 ms 21972 KB Output is correct
22 Correct 163 ms 22164 KB Output is correct
23 Correct 153 ms 22076 KB Output is correct
24 Correct 152 ms 22116 KB Output is correct
25 Correct 63 ms 12056 KB Output is correct
26 Correct 60 ms 12056 KB Output is correct
27 Correct 159 ms 22128 KB Output is correct
28 Correct 151 ms 22096 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 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 1 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 8 ms 1116 KB Output is correct
37 Correct 159 ms 22028 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 6 ms 1116 KB Output is correct
41 Correct 153 ms 22264 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 68 ms 12256 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 37 ms 5744 KB Output is correct
50 Correct 158 ms 22036 KB Output is correct
51 Correct 151 ms 22024 KB Output is correct
52 Correct 161 ms 22276 KB Output is correct
53 Correct 68 ms 12116 KB Output is correct
54 Incorrect 151 ms 22104 KB Answer gives possible 1 while actual possible 0
55 Halted 0 ms 0 KB -