Submission #963847

# Submission time Handle Problem Language Result Execution time Memory
963847 2024-04-15T19:42:00 Z nguyentunglam Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
177 ms 24316 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]) {
    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 (p[connected[i][0]][connected[j][0]] == 2) {
      if (vis[j]) return 0;
      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 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:50:22: 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 j = 0; j < connected.size(); j++) if (p[connected[i][0]][connected[j][0]] == 2) {
      |                    ~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     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 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 1396 KB Output is correct
7 Correct 172 ms 24188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 1396 KB Output is correct
7 Correct 172 ms 24188 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 1 ms 344 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 163 ms 24316 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 432 KB Output is correct
16 Correct 3 ms 932 KB Output is correct
17 Correct 70 ms 14196 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 37 ms 6324 KB Output is correct
21 Correct 165 ms 24008 KB Output is correct
22 Correct 153 ms 24048 KB Output is correct
23 Correct 158 ms 24088 KB Output is correct
24 Correct 177 ms 24204 KB Output is correct
25 Correct 62 ms 14160 KB Output is correct
26 Correct 62 ms 14164 KB Output is correct
27 Correct 156 ms 24148 KB Output is correct
28 Correct 153 ms 24148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 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 7 ms 1372 KB Output is correct
9 Correct 162 ms 24060 KB Output is correct
10 Incorrect 1 ms 348 KB Too many ways to get from 0 to 3, should be 2 found no less than 3
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 38 ms 6324 KB Output is correct
5 Correct 147 ms 24036 KB Output is correct
6 Correct 149 ms 23984 KB Output is correct
7 Correct 158 ms 23992 KB Output is correct
8 Incorrect 1 ms 344 KB Too many ways to get from 0 to 2, should be 2 found no less than 3
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 1396 KB Output is correct
7 Correct 172 ms 24188 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 1 ms 344 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 163 ms 24316 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 432 KB Output is correct
16 Correct 3 ms 932 KB Output is correct
17 Correct 70 ms 14196 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 37 ms 6324 KB Output is correct
21 Correct 165 ms 24008 KB Output is correct
22 Correct 153 ms 24048 KB Output is correct
23 Correct 158 ms 24088 KB Output is correct
24 Correct 177 ms 24204 KB Output is correct
25 Correct 62 ms 14160 KB Output is correct
26 Correct 62 ms 14164 KB Output is correct
27 Correct 156 ms 24148 KB Output is correct
28 Correct 153 ms 24148 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 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 7 ms 1372 KB Output is correct
37 Correct 162 ms 24060 KB Output is correct
38 Incorrect 1 ms 348 KB Too many ways to get from 0 to 3, should be 2 found no less than 3
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 1396 KB Output is correct
7 Correct 172 ms 24188 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 1 ms 344 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 163 ms 24316 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 432 KB Output is correct
16 Correct 3 ms 932 KB Output is correct
17 Correct 70 ms 14196 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 37 ms 6324 KB Output is correct
21 Correct 165 ms 24008 KB Output is correct
22 Correct 153 ms 24048 KB Output is correct
23 Correct 158 ms 24088 KB Output is correct
24 Correct 177 ms 24204 KB Output is correct
25 Correct 62 ms 14160 KB Output is correct
26 Correct 62 ms 14164 KB Output is correct
27 Correct 156 ms 24148 KB Output is correct
28 Correct 153 ms 24148 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 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 7 ms 1372 KB Output is correct
37 Correct 162 ms 24060 KB Output is correct
38 Incorrect 1 ms 348 KB Too many ways to get from 0 to 3, should be 2 found no less than 3
39 Halted 0 ms 0 KB -