Submission #388396

# Submission time Handle Problem Language Result Execution time Memory
388396 2021-04-11T10:30:51 Z WLZ Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
300 ms 24212 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

vector< vector<int> > ans;
vector<int> p;

int root(int x) {
  if (p[x] == -1) return x;
  return p[x] = root(p[x]);
}

void connect(int x, int y, bool b = true) {
  x = root(x); y = root(y);
  if (x != y) {
    p[y] = x;
    if (b) ans[x][y] = ans[y][x] = 1;
  }
}

int construct(vector< vector<int> > a) {
	int n = a.size();
  ans.assign(n, vector<int>(n, 0));
  p.assign(n, -1);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] >= 3) return 0;
      if (a[i][j] == 1) connect(i, j);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (root(i) == root(j) && a[i][j] != 1) return 0;
    }
  }
  vector<bool> is_root(n);
  for (int i = 0; i < n; i++) is_root[i] = root(i) == i;
  p.assign(n, -1);
  for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (is_root[i] && is_root[j] && a[i][j] == 2) connect(i, j, false);
  for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j && root(i) == root(j) && a[i][j] != 2) return 0; 
  for (int i = 0; i < n; i++) {
    if (root(i) != i) continue;
    vector<int> tmp;
    for (int j = 0; j < n; j++) if (root(j) == i) tmp.push_back(j);
    if ((int) tmp.size() == 1) continue;
    if ((int) tmp.size() == 2) return 0;
    for (int i = 1; i < (int) tmp.size(); i++) ans[tmp[i - 1]][tmp[i]] = ans[tmp[i]][tmp[i - 1]] = 1;
    ans[tmp[0]][tmp.back()] = ans[tmp.back()][tmp[0]] = 1;
  }
  build(ans);
  return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1252 KB Output is correct
7 Correct 273 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1252 KB Output is correct
7 Correct 273 ms 23936 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 10 ms 1252 KB Output is correct
13 Correct 247 ms 23892 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 800 KB Output is correct
17 Correct 133 ms 14084 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 73 ms 6336 KB Output is correct
21 Correct 257 ms 24188 KB Output is correct
22 Correct 252 ms 23924 KB Output is correct
23 Correct 270 ms 24004 KB Output is correct
24 Correct 245 ms 24004 KB Output is correct
25 Correct 103 ms 14068 KB Output is correct
26 Correct 104 ms 14084 KB Output is correct
27 Correct 269 ms 24064 KB Output is correct
28 Correct 243 ms 23932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 10 ms 1228 KB Output is correct
9 Correct 262 ms 23924 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 11 ms 1228 KB Output is correct
13 Correct 250 ms 23924 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 940 KB Output is correct
17 Correct 120 ms 14076 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 63 ms 6180 KB Output is correct
22 Correct 288 ms 23992 KB Output is correct
23 Correct 250 ms 24004 KB Output is correct
24 Correct 292 ms 24212 KB Output is correct
25 Correct 138 ms 14068 KB Output is correct
26 Correct 110 ms 14080 KB Output is correct
27 Correct 257 ms 23932 KB Output is correct
28 Correct 264 ms 23888 KB Output is correct
29 Correct 106 ms 14020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 64 ms 6144 KB Output is correct
5 Correct 257 ms 24036 KB Output is correct
6 Correct 256 ms 23932 KB Output is correct
7 Correct 300 ms 24008 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 67 ms 6212 KB Output is correct
10 Correct 250 ms 23932 KB Output is correct
11 Correct 252 ms 23988 KB Output is correct
12 Correct 266 ms 23944 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 64 ms 6252 KB Output is correct
17 Correct 253 ms 23928 KB Output is correct
18 Correct 259 ms 24004 KB Output is correct
19 Correct 261 ms 24004 KB Output is correct
20 Correct 246 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1252 KB Output is correct
7 Correct 273 ms 23936 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 10 ms 1252 KB Output is correct
13 Correct 247 ms 23892 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 800 KB Output is correct
17 Correct 133 ms 14084 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 73 ms 6336 KB Output is correct
21 Correct 257 ms 24188 KB Output is correct
22 Correct 252 ms 23924 KB Output is correct
23 Correct 270 ms 24004 KB Output is correct
24 Correct 245 ms 24004 KB Output is correct
25 Correct 103 ms 14068 KB Output is correct
26 Correct 104 ms 14084 KB Output is correct
27 Correct 269 ms 24064 KB Output is correct
28 Correct 243 ms 23932 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1228 KB Output is correct
37 Correct 262 ms 23924 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 11 ms 1228 KB Output is correct
41 Correct 250 ms 23924 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 940 KB Output is correct
45 Correct 120 ms 14076 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 63 ms 6180 KB Output is correct
50 Correct 288 ms 23992 KB Output is correct
51 Correct 250 ms 24004 KB Output is correct
52 Correct 292 ms 24212 KB Output is correct
53 Correct 138 ms 14068 KB Output is correct
54 Correct 110 ms 14080 KB Output is correct
55 Correct 257 ms 23932 KB Output is correct
56 Correct 264 ms 23888 KB Output is correct
57 Correct 106 ms 14020 KB Output is correct
58 Correct 1 ms 304 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 5 ms 844 KB Output is correct
61 Correct 112 ms 14072 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 63 ms 6260 KB Output is correct
66 Correct 111 ms 14076 KB Output is correct
67 Correct 107 ms 13992 KB Output is correct
68 Correct 126 ms 14080 KB Output is correct
69 Correct 126 ms 14080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 11 ms 1252 KB Output is correct
7 Correct 273 ms 23936 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 10 ms 1252 KB Output is correct
13 Correct 247 ms 23892 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 800 KB Output is correct
17 Correct 133 ms 14084 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 73 ms 6336 KB Output is correct
21 Correct 257 ms 24188 KB Output is correct
22 Correct 252 ms 23924 KB Output is correct
23 Correct 270 ms 24004 KB Output is correct
24 Correct 245 ms 24004 KB Output is correct
25 Correct 103 ms 14068 KB Output is correct
26 Correct 104 ms 14084 KB Output is correct
27 Correct 269 ms 24064 KB Output is correct
28 Correct 243 ms 23932 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 10 ms 1228 KB Output is correct
37 Correct 262 ms 23924 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 11 ms 1228 KB Output is correct
41 Correct 250 ms 23924 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 5 ms 940 KB Output is correct
45 Correct 120 ms 14076 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 63 ms 6180 KB Output is correct
50 Correct 288 ms 23992 KB Output is correct
51 Correct 250 ms 24004 KB Output is correct
52 Correct 292 ms 24212 KB Output is correct
53 Correct 138 ms 14068 KB Output is correct
54 Correct 110 ms 14080 KB Output is correct
55 Correct 257 ms 23932 KB Output is correct
56 Correct 264 ms 23888 KB Output is correct
57 Correct 106 ms 14020 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 64 ms 6144 KB Output is correct
62 Correct 257 ms 24036 KB Output is correct
63 Correct 256 ms 23932 KB Output is correct
64 Correct 300 ms 24008 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 67 ms 6212 KB Output is correct
67 Correct 250 ms 23932 KB Output is correct
68 Correct 252 ms 23988 KB Output is correct
69 Correct 266 ms 23944 KB Output is correct
70 Correct 0 ms 204 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 64 ms 6252 KB Output is correct
74 Correct 253 ms 23928 KB Output is correct
75 Correct 259 ms 24004 KB Output is correct
76 Correct 261 ms 24004 KB Output is correct
77 Correct 246 ms 23936 KB Output is correct
78 Correct 1 ms 304 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 5 ms 844 KB Output is correct
81 Correct 112 ms 14072 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 1 ms 204 KB Output is correct
84 Correct 0 ms 204 KB Output is correct
85 Correct 63 ms 6260 KB Output is correct
86 Correct 111 ms 14076 KB Output is correct
87 Correct 107 ms 13992 KB Output is correct
88 Correct 126 ms 14080 KB Output is correct
89 Correct 126 ms 14080 KB Output is correct
90 Correct 0 ms 204 KB Output is correct
91 Correct 0 ms 204 KB Output is correct
92 Correct 5 ms 844 KB Output is correct
93 Correct 102 ms 14084 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 1 ms 292 KB Output is correct
96 Correct 0 ms 204 KB Output is correct
97 Correct 26 ms 3708 KB Output is correct
98 Correct 103 ms 14080 KB Output is correct
99 Correct 101 ms 14064 KB Output is correct
100 Correct 99 ms 14072 KB Output is correct
101 Correct 102 ms 14084 KB Output is correct
102 Correct 99 ms 14004 KB Output is correct
103 Correct 101 ms 14020 KB Output is correct
104 Correct 100 ms 14068 KB Output is correct
105 Correct 104 ms 14080 KB Output is correct