Submission #437664

# Submission time Handle Problem Language Result Execution time Memory
437664 2021-06-26T19:00:07 Z xiaowuc1 Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
310 ms 24208 KB
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include "supertrees.h"

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
// END NO SAD
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> matrix;
 
int find(vector<int>& p, int x) {
  return p[x] == x ? x : (p[x] = find(p, p[x]));
}
void merge(vector<int>& p, int x, int y) {
  p[find(p, x)] = find(p, y);
}
 
int construct(vector<vector<int>> p) {
  int n = sz(p);
  vector<vector<int>> ret;
  for(int i = 0; i < n; i++) {
    vector<int> t(n);
    ret.pb(t);
  }
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] == 3) return 0;
  vector<int> connectedcomponent(n);
  iota(all(connectedcomponent), 0);
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j]) merge(connectedcomponent, i, j);
  // check zero
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] == 0 && find(connectedcomponent, i) == find(connectedcomponent, j)) return 0;
  // check one
  vector<int> oneedge(n);
  iota(all(oneedge), 0);
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] == 1) merge(oneedge, i, j);
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) {
		if(p[i][j] == 0) continue;
		if(p[i][j] != 1 && find(oneedge, i) == find(oneedge, j)) return 0; 
	}
  map<int, int> treetoroot;
  for(int i = 0; i < n; i++) {
    if(!treetoroot.count(find(oneedge, i))) {
      treetoroot[find(oneedge, i)] = i;
    }
    else {
      ret[treetoroot[find(oneedge, i)]][i] = 1;
      ret[i][treetoroot[find(oneedge, i)]] = 1;
    }
  }
  map<int, set<int>> roots;
  for(int i = 0; i < n; i++) {
    roots[find(connectedcomponent, i)].insert(treetoroot[find(oneedge, i)]);
  }
  for(auto out: roots) {
		cerr << out.f << " has roots:";
		for(auto out2: out.s) cerr << " " << out2; cerr << endl;
    if(sz(out.s) == 2) return 0;
    if(sz(out.s) == 1) continue;
    vector<int> v(all(out.s));
    for(int i = 0; i < sz(v); i++) {
      int j = (i+1)%sz(v);
      ret[v[i]][v[j]] = 1;
      ret[v[j]][v[i]] = 1;
    }
  }
  build(ret);
  return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:83:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   83 |   for(auto out2: out.s) cerr << " " << out2; cerr << endl;
      |   ^~~
supertrees.cpp:83:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   83 |   for(auto out2: out.s) cerr << " " << out2; cerr << endl;
      |                                              ^~~~
# 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 1 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 1124 KB Output is correct
7 Correct 256 ms 22024 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 1 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 1124 KB Output is correct
7 Correct 256 ms 22024 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 14 ms 1152 KB Output is correct
13 Correct 255 ms 22264 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 716 KB Output is correct
17 Correct 116 ms 12036 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 66 ms 5700 KB Output is correct
21 Correct 249 ms 22016 KB Output is correct
22 Correct 240 ms 22012 KB Output is correct
23 Correct 270 ms 21956 KB Output is correct
24 Correct 242 ms 22224 KB Output is correct
25 Correct 130 ms 12100 KB Output is correct
26 Correct 96 ms 12036 KB Output is correct
27 Correct 263 ms 22000 KB Output is correct
28 Correct 254 ms 22136 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 1 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 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 12 ms 1244 KB Output is correct
9 Correct 249 ms 24160 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 11 ms 1256 KB Output is correct
13 Correct 249 ms 23996 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 6 ms 844 KB Output is correct
17 Correct 119 ms 14068 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 83 ms 6196 KB Output is correct
22 Correct 251 ms 24180 KB Output is correct
23 Correct 243 ms 24004 KB Output is correct
24 Correct 260 ms 24004 KB Output is correct
25 Correct 111 ms 14184 KB Output is correct
26 Correct 105 ms 14060 KB Output is correct
27 Correct 244 ms 24060 KB Output is correct
28 Correct 310 ms 24004 KB Output is correct
29 Correct 109 ms 14276 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 1 ms 204 KB Output is correct
4 Correct 66 ms 6252 KB Output is correct
5 Correct 259 ms 24036 KB Output is correct
6 Correct 248 ms 24088 KB Output is correct
7 Correct 283 ms 24004 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 63 ms 6248 KB Output is correct
10 Correct 257 ms 24036 KB Output is correct
11 Correct 246 ms 24004 KB Output is correct
12 Correct 261 ms 24004 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 62 ms 6252 KB Output is correct
17 Correct 248 ms 24012 KB Output is correct
18 Correct 253 ms 24056 KB Output is correct
19 Correct 255 ms 24208 KB Output is correct
20 Correct 252 ms 24156 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 1 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 1124 KB Output is correct
7 Correct 256 ms 22024 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 14 ms 1152 KB Output is correct
13 Correct 255 ms 22264 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 716 KB Output is correct
17 Correct 116 ms 12036 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 66 ms 5700 KB Output is correct
21 Correct 249 ms 22016 KB Output is correct
22 Correct 240 ms 22012 KB Output is correct
23 Correct 270 ms 21956 KB Output is correct
24 Correct 242 ms 22224 KB Output is correct
25 Correct 130 ms 12100 KB Output is correct
26 Correct 96 ms 12036 KB Output is correct
27 Correct 263 ms 22000 KB Output is correct
28 Correct 254 ms 22136 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 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 12 ms 1244 KB Output is correct
37 Correct 249 ms 24160 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1256 KB Output is correct
41 Correct 249 ms 23996 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 292 KB Output is correct
44 Correct 6 ms 844 KB Output is correct
45 Correct 119 ms 14068 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 83 ms 6196 KB Output is correct
50 Correct 251 ms 24180 KB Output is correct
51 Correct 243 ms 24004 KB Output is correct
52 Correct 260 ms 24004 KB Output is correct
53 Correct 111 ms 14184 KB Output is correct
54 Correct 105 ms 14060 KB Output is correct
55 Correct 244 ms 24060 KB Output is correct
56 Correct 310 ms 24004 KB Output is correct
57 Correct 109 ms 14276 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 6 ms 844 KB Output is correct
61 Correct 120 ms 14060 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 67 ms 6248 KB Output is correct
66 Correct 106 ms 14068 KB Output is correct
67 Correct 100 ms 14076 KB Output is correct
68 Correct 104 ms 14020 KB Output is correct
69 Correct 137 ms 14188 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 1 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 1124 KB Output is correct
7 Correct 256 ms 22024 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 14 ms 1152 KB Output is correct
13 Correct 255 ms 22264 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 716 KB Output is correct
17 Correct 116 ms 12036 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 66 ms 5700 KB Output is correct
21 Correct 249 ms 22016 KB Output is correct
22 Correct 240 ms 22012 KB Output is correct
23 Correct 270 ms 21956 KB Output is correct
24 Correct 242 ms 22224 KB Output is correct
25 Correct 130 ms 12100 KB Output is correct
26 Correct 96 ms 12036 KB Output is correct
27 Correct 263 ms 22000 KB Output is correct
28 Correct 254 ms 22136 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 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 12 ms 1244 KB Output is correct
37 Correct 249 ms 24160 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 11 ms 1256 KB Output is correct
41 Correct 249 ms 23996 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 292 KB Output is correct
44 Correct 6 ms 844 KB Output is correct
45 Correct 119 ms 14068 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 83 ms 6196 KB Output is correct
50 Correct 251 ms 24180 KB Output is correct
51 Correct 243 ms 24004 KB Output is correct
52 Correct 260 ms 24004 KB Output is correct
53 Correct 111 ms 14184 KB Output is correct
54 Correct 105 ms 14060 KB Output is correct
55 Correct 244 ms 24060 KB Output is correct
56 Correct 310 ms 24004 KB Output is correct
57 Correct 109 ms 14276 KB Output is correct
58 Correct 1 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 66 ms 6252 KB Output is correct
62 Correct 259 ms 24036 KB Output is correct
63 Correct 248 ms 24088 KB Output is correct
64 Correct 283 ms 24004 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 63 ms 6248 KB Output is correct
67 Correct 257 ms 24036 KB Output is correct
68 Correct 246 ms 24004 KB Output is correct
69 Correct 261 ms 24004 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 62 ms 6252 KB Output is correct
74 Correct 248 ms 24012 KB Output is correct
75 Correct 253 ms 24056 KB Output is correct
76 Correct 255 ms 24208 KB Output is correct
77 Correct 252 ms 24156 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 6 ms 844 KB Output is correct
81 Correct 120 ms 14060 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 1 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 67 ms 6248 KB Output is correct
86 Correct 106 ms 14068 KB Output is correct
87 Correct 100 ms 14076 KB Output is correct
88 Correct 104 ms 14020 KB Output is correct
89 Correct 137 ms 14188 KB Output is correct
90 Correct 1 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 5 ms 796 KB Output is correct
93 Correct 105 ms 14068 KB Output is correct
94 Correct 1 ms 236 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 30 ms 3692 KB Output is correct
98 Correct 97 ms 14020 KB Output is correct
99 Correct 101 ms 14076 KB Output is correct
100 Correct 103 ms 13984 KB Output is correct
101 Correct 110 ms 14020 KB Output is correct
102 Correct 100 ms 14020 KB Output is correct
103 Correct 99 ms 14076 KB Output is correct
104 Correct 120 ms 14020 KB Output is correct
105 Correct 113 ms 14072 KB Output is correct