Submission #771025

# Submission time Handle Problem Language Result Execution time Memory
771025 2023-07-02T11:07:30 Z cadmiumsky Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
175 ms 27760 KB
#include <bits/stdc++.h>
#include "supertrees.h"
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

//#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

vector<vector<int>> rez;

void addedge(int a, int b) {
  rez[a][b] = rez[b][a] = 1;
  return;
}

int construct(std::vector<std::vector<int>> p) {
  int n;
  for(auto v : p)
    for(auto x : v) {
      if(x == 3) return 0;
    } 
  n = sz(p);
  for(int i = 0; i < n; i++)
    if(p[i][i] != 1) return 0;
  rez.resize(n, vector<int>(n, 0));
  //cerr << n << '\n';
  map<vector<int>, vector<int>> group;
  vector<int> eligible(n, 0);
  for(int i = 0; i < n; i++) 
    group[p[i]].emplace_back(i);
  
  for(auto &[a, b] : group) {
    //cerr << sz(b) << '\n';
    for(int i = 1; i < sz(b); i++)
      addedge(b[0], b[i]);
    eligible[b[0]] = 1;
  }
  //cerr << "ok\n";
  group.clear();
    
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      p[i][j] *= eligible[i] * eligible[j];
      if(i == j) p[i][j] *= 2;
      if(p[i][j] == 1) return 0;
    }
    if(eligible[i])
      group[p[i]].emplace_back(i);
  }
  
  vector<int> coloring(n);
  int C = 0;
  
  for(auto &[a, b] : group) {
    C++;
    for(auto x : b)
      coloring[x] = C;
    if(sz(b) == 1) continue;
    if(sz(b) == 2) return 0;
    for(int i = 0, j = 1; i < sz(b); i++, j = (j + 1) % sz(b)) {
      addedge(b[i], b[j]);
    }
  }
  
  for(int i = 0; i < n; i++) {
    if(!eligible[i]) continue;
    for(int j = 0; j < n; j++) {
      if(!eligible[j]) continue;
      if(p[i][j] == 2) {
        if(!(coloring[i] == coloring[j]))
          return 0;
      }
        
    }
  }
  
  build(rez);
  return 1;
  

}



/**
      Anul asta se da centroid.
-- Surse oficiale
*/

# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 154 ms 22028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 154 ms 22028 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 1368 KB Output is correct
13 Correct 163 ms 26048 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 67 ms 16132 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 44 ms 5844 KB Output is correct
21 Correct 153 ms 22092 KB Output is correct
22 Correct 155 ms 23648 KB Output is correct
23 Correct 158 ms 22000 KB Output is correct
24 Correct 162 ms 25820 KB Output is correct
25 Correct 66 ms 12176 KB Output is correct
26 Correct 65 ms 13716 KB Output is correct
27 Correct 156 ms 22024 KB Output is correct
28 Correct 162 ms 25860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1364 KB Output is correct
9 Correct 163 ms 25996 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 308 KB Output is correct
12 Correct 7 ms 1212 KB Output is correct
13 Correct 165 ms 23972 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 956 KB Output is correct
17 Correct 71 ms 18040 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 296 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 40 ms 6352 KB Output is correct
22 Correct 158 ms 24060 KB Output is correct
23 Correct 157 ms 24764 KB Output is correct
24 Correct 175 ms 24036 KB Output is correct
25 Correct 77 ms 18032 KB Output is correct
26 Correct 69 ms 18028 KB Output is correct
27 Correct 159 ms 24796 KB Output is correct
28 Correct 165 ms 23932 KB Output is correct
29 Correct 75 ms 18036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 52 ms 5852 KB Output is correct
5 Correct 154 ms 22036 KB Output is correct
6 Correct 157 ms 23680 KB Output is correct
7 Correct 163 ms 22164 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 40 ms 6308 KB Output is correct
10 Correct 157 ms 24060 KB Output is correct
11 Correct 163 ms 24784 KB Output is correct
12 Correct 166 ms 23940 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 45 ms 6504 KB Output is correct
17 Correct 157 ms 24052 KB Output is correct
18 Correct 157 ms 24012 KB Output is correct
19 Correct 161 ms 24176 KB Output is correct
20 Correct 166 ms 27760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 154 ms 22028 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 1368 KB Output is correct
13 Correct 163 ms 26048 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 67 ms 16132 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 44 ms 5844 KB Output is correct
21 Correct 153 ms 22092 KB Output is correct
22 Correct 155 ms 23648 KB Output is correct
23 Correct 158 ms 22000 KB Output is correct
24 Correct 162 ms 25820 KB Output is correct
25 Correct 66 ms 12176 KB Output is correct
26 Correct 65 ms 13716 KB Output is correct
27 Correct 156 ms 22024 KB Output is correct
28 Correct 162 ms 25860 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1364 KB Output is correct
37 Correct 163 ms 25996 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 308 KB Output is correct
40 Correct 7 ms 1212 KB Output is correct
41 Correct 165 ms 23972 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 956 KB Output is correct
45 Correct 71 ms 18040 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 296 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 40 ms 6352 KB Output is correct
50 Correct 158 ms 24060 KB Output is correct
51 Correct 157 ms 24764 KB Output is correct
52 Correct 175 ms 24036 KB Output is correct
53 Correct 77 ms 18032 KB Output is correct
54 Correct 69 ms 18028 KB Output is correct
55 Correct 159 ms 24796 KB Output is correct
56 Correct 165 ms 23932 KB Output is correct
57 Correct 75 ms 18036 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 3 ms 980 KB Output is correct
61 Correct 72 ms 18048 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 40 ms 6388 KB Output is correct
66 Correct 67 ms 18124 KB Output is correct
67 Correct 66 ms 16640 KB Output is correct
68 Correct 64 ms 16248 KB Output is correct
69 Correct 75 ms 17916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 154 ms 22028 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 1368 KB Output is correct
13 Correct 163 ms 26048 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 67 ms 16132 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 44 ms 5844 KB Output is correct
21 Correct 153 ms 22092 KB Output is correct
22 Correct 155 ms 23648 KB Output is correct
23 Correct 158 ms 22000 KB Output is correct
24 Correct 162 ms 25820 KB Output is correct
25 Correct 66 ms 12176 KB Output is correct
26 Correct 65 ms 13716 KB Output is correct
27 Correct 156 ms 22024 KB Output is correct
28 Correct 162 ms 25860 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1364 KB Output is correct
37 Correct 163 ms 25996 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 308 KB Output is correct
40 Correct 7 ms 1212 KB Output is correct
41 Correct 165 ms 23972 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 956 KB Output is correct
45 Correct 71 ms 18040 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 296 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 40 ms 6352 KB Output is correct
50 Correct 158 ms 24060 KB Output is correct
51 Correct 157 ms 24764 KB Output is correct
52 Correct 175 ms 24036 KB Output is correct
53 Correct 77 ms 18032 KB Output is correct
54 Correct 69 ms 18028 KB Output is correct
55 Correct 159 ms 24796 KB Output is correct
56 Correct 165 ms 23932 KB Output is correct
57 Correct 75 ms 18036 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 52 ms 5852 KB Output is correct
62 Correct 154 ms 22036 KB Output is correct
63 Correct 157 ms 23680 KB Output is correct
64 Correct 163 ms 22164 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 40 ms 6308 KB Output is correct
67 Correct 157 ms 24060 KB Output is correct
68 Correct 163 ms 24784 KB Output is correct
69 Correct 166 ms 23940 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 288 KB Output is correct
73 Correct 45 ms 6504 KB Output is correct
74 Correct 157 ms 24052 KB Output is correct
75 Correct 157 ms 24012 KB Output is correct
76 Correct 161 ms 24176 KB Output is correct
77 Correct 166 ms 27760 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 3 ms 980 KB Output is correct
81 Correct 72 ms 18048 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 40 ms 6388 KB Output is correct
86 Correct 67 ms 18124 KB Output is correct
87 Correct 66 ms 16640 KB Output is correct
88 Correct 64 ms 16248 KB Output is correct
89 Correct 75 ms 17916 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 3 ms 596 KB Output is correct
93 Correct 62 ms 10096 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 1 ms 300 KB Output is correct
97 Correct 18 ms 2672 KB Output is correct
98 Correct 62 ms 10112 KB Output is correct
99 Correct 60 ms 10108 KB Output is correct
100 Correct 59 ms 10096 KB Output is correct
101 Correct 60 ms 10100 KB Output is correct
102 Correct 70 ms 10060 KB Output is correct
103 Correct 61 ms 10096 KB Output is correct
104 Correct 60 ms 10096 KB Output is correct
105 Correct 65 ms 10112 KB Output is correct