Submission #713396

# Submission time Handle Problem Language Result Execution time Memory
713396 2023-03-21T21:26:41 Z garyye Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
205 ms 28160 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
template<class T> bool cmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template<class T> bool cmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
typedef pair<int, int> pii;
#define SZ(x) ((int) (x.size()))
#define fi first
#define se second

const int N = 2222;
int n;
int vis[N];
int root[N];

vector<vector<int>> p, b;
vector<int> roots, t;

void add(int u, int v) {
  b[u][v] = b[v][u] = 1;
}

void dfs(int u) {
  t.push_back(u);
  vis[u] = 1;
  for(int v = 0; v < n; ++v) {
    if(u == v || vis[v] || p[u][v] != 1) 
      continue;
    dfs(v);
  }
}

void rec(int u) {
  vis[u] = true;
  t.push_back(u);
  for(int v: roots) {
    if(p[u][v] == 2 && !vis[v]) {
      rec(v);
    }
  }
}

int construct(vector<vector<int>> _p) { 
  p = _p;
  n = p.size();
  b = vector<vector<int>>(n, vector<int>(n, 0));

  // Last subtask
  for(auto& a: p) 
    for(auto& b: a) 
      if(b == 3) 
        return 0;

  for(int foo = 0; foo < n; foo++) {
    if(vis[foo])
      continue;
    t.clear();
    dfs(foo);
    for(int i: t) {
      for(int j = 0; j < n; ++j) {
        if(p[i][j] != p[t[0]][j]) {
          return 0;
        }
      }
    }
    // Can name anyone the root since they all the same
    for(int i = 0; i + 1 < SZ(t); ++i) {
      add(t[i], t[i + 1]);
      root[t[i + 1]] = t[0];
    }
    roots.push_back(t[0]);
  }

  memset(vis, 0, sizeof vis);
  for(int u: roots) {
    if(vis[u])
      continue;
    t.clear();
    rec(u);

    if(SZ(t) == 2)
      return 0;
    if(SZ(t) == 1)
      continue;
    for(int x: t) 
      for(int y: t) 
        if(x != y && p[x][y] != 2)
          return 0;
    for(int i = 0; i < SZ(t); ++i) {
      add(t[i], t[(i+1)%SZ(t)]);
    }
  }

  build(b);
  return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1408 KB Output is correct
7 Correct 162 ms 27912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1408 KB Output is correct
7 Correct 162 ms 27912 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1340 KB Output is correct
13 Correct 162 ms 27916 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 74 ms 18044 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 41 ms 7276 KB Output is correct
21 Correct 164 ms 27896 KB Output is correct
22 Correct 165 ms 27980 KB Output is correct
23 Correct 171 ms 28160 KB Output is correct
24 Correct 168 ms 27904 KB Output is correct
25 Correct 72 ms 17972 KB Output is correct
26 Correct 66 ms 18048 KB Output is correct
27 Correct 173 ms 27952 KB Output is correct
28 Correct 163 ms 27980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 7 ms 1340 KB Output is correct
9 Correct 164 ms 27924 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 165 ms 28032 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 86 ms 18048 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 51 ms 7312 KB Output is correct
22 Correct 167 ms 27904 KB Output is correct
23 Correct 164 ms 27980 KB Output is correct
24 Correct 172 ms 27904 KB Output is correct
25 Correct 68 ms 18124 KB Output is correct
26 Correct 69 ms 18064 KB Output is correct
27 Correct 163 ms 27944 KB Output is correct
28 Correct 180 ms 28032 KB Output is correct
29 Correct 85 ms 18064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 44 ms 7244 KB Output is correct
5 Correct 165 ms 27924 KB Output is correct
6 Correct 165 ms 27916 KB Output is correct
7 Correct 169 ms 27916 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 43 ms 7188 KB Output is correct
10 Correct 171 ms 27904 KB Output is correct
11 Correct 171 ms 27900 KB Output is correct
12 Correct 205 ms 27980 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 43 ms 7160 KB Output is correct
17 Correct 168 ms 27912 KB Output is correct
18 Correct 164 ms 27980 KB Output is correct
19 Correct 171 ms 27980 KB Output is correct
20 Correct 169 ms 27912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1408 KB Output is correct
7 Correct 162 ms 27912 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1340 KB Output is correct
13 Correct 162 ms 27916 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 74 ms 18044 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 41 ms 7276 KB Output is correct
21 Correct 164 ms 27896 KB Output is correct
22 Correct 165 ms 27980 KB Output is correct
23 Correct 171 ms 28160 KB Output is correct
24 Correct 168 ms 27904 KB Output is correct
25 Correct 72 ms 17972 KB Output is correct
26 Correct 66 ms 18048 KB Output is correct
27 Correct 173 ms 27952 KB Output is correct
28 Correct 163 ms 27980 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 304 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 304 KB Output is correct
36 Correct 7 ms 1340 KB Output is correct
37 Correct 164 ms 27924 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1364 KB Output is correct
41 Correct 165 ms 28032 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 980 KB Output is correct
45 Correct 86 ms 18048 KB Output is correct
46 Correct 1 ms 308 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 51 ms 7312 KB Output is correct
50 Correct 167 ms 27904 KB Output is correct
51 Correct 164 ms 27980 KB Output is correct
52 Correct 172 ms 27904 KB Output is correct
53 Correct 68 ms 18124 KB Output is correct
54 Correct 69 ms 18064 KB Output is correct
55 Correct 163 ms 27944 KB Output is correct
56 Correct 180 ms 28032 KB Output is correct
57 Correct 85 ms 18064 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 4 ms 980 KB Output is correct
61 Correct 71 ms 18060 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 42 ms 7192 KB Output is correct
66 Correct 66 ms 18048 KB Output is correct
67 Correct 74 ms 17968 KB Output is correct
68 Correct 66 ms 18048 KB Output is correct
69 Correct 67 ms 18060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 8 ms 1408 KB Output is correct
7 Correct 162 ms 27912 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 8 ms 1340 KB Output is correct
13 Correct 162 ms 27916 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 74 ms 18044 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 41 ms 7276 KB Output is correct
21 Correct 164 ms 27896 KB Output is correct
22 Correct 165 ms 27980 KB Output is correct
23 Correct 171 ms 28160 KB Output is correct
24 Correct 168 ms 27904 KB Output is correct
25 Correct 72 ms 17972 KB Output is correct
26 Correct 66 ms 18048 KB Output is correct
27 Correct 173 ms 27952 KB Output is correct
28 Correct 163 ms 27980 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 304 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 304 KB Output is correct
36 Correct 7 ms 1340 KB Output is correct
37 Correct 164 ms 27924 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1364 KB Output is correct
41 Correct 165 ms 28032 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 980 KB Output is correct
45 Correct 86 ms 18048 KB Output is correct
46 Correct 1 ms 308 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 51 ms 7312 KB Output is correct
50 Correct 167 ms 27904 KB Output is correct
51 Correct 164 ms 27980 KB Output is correct
52 Correct 172 ms 27904 KB Output is correct
53 Correct 68 ms 18124 KB Output is correct
54 Correct 69 ms 18064 KB Output is correct
55 Correct 163 ms 27944 KB Output is correct
56 Correct 180 ms 28032 KB Output is correct
57 Correct 85 ms 18064 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 308 KB Output is correct
61 Correct 44 ms 7244 KB Output is correct
62 Correct 165 ms 27924 KB Output is correct
63 Correct 165 ms 27916 KB Output is correct
64 Correct 169 ms 27916 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 43 ms 7188 KB Output is correct
67 Correct 171 ms 27904 KB Output is correct
68 Correct 171 ms 27900 KB Output is correct
69 Correct 205 ms 27980 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 43 ms 7160 KB Output is correct
74 Correct 168 ms 27912 KB Output is correct
75 Correct 164 ms 27980 KB Output is correct
76 Correct 171 ms 27980 KB Output is correct
77 Correct 169 ms 27912 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 4 ms 980 KB Output is correct
81 Correct 71 ms 18060 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 42 ms 7192 KB Output is correct
86 Correct 66 ms 18048 KB Output is correct
87 Correct 74 ms 17968 KB Output is correct
88 Correct 66 ms 18048 KB Output is correct
89 Correct 67 ms 18060 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 304 KB Output is correct
92 Correct 4 ms 960 KB Output is correct
93 Correct 69 ms 17928 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 17 ms 4684 KB Output is correct
98 Correct 66 ms 18060 KB Output is correct
99 Correct 67 ms 18052 KB Output is correct
100 Correct 65 ms 18040 KB Output is correct
101 Correct 69 ms 18128 KB Output is correct
102 Correct 66 ms 18052 KB Output is correct
103 Correct 65 ms 18044 KB Output is correct
104 Correct 65 ms 18048 KB Output is correct
105 Correct 78 ms 18048 KB Output is correct