//나는 가상 소녀들에게 큰 호감이 있습니다.
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define sz(a) (int)(a.size())
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define problem "a"
template<typename A, typename B, typename C>
struct triple {
A X;
B Y;
C Z;
triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) {
return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b) {
if (a.X != b.X)
return a.X < b.X;
if (a.Y != b.Y)
return a.Y < b.Y;
return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p) {
ofs << "( " << p.F << " , " << p.S << " )";
return ofs;
}
template<typename T>
void print(T a) {
for (auto i : a)
cout << i << ' ';
cout << '\n';
}
template<typename T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template<typename T, typename D>
D min(T a) {
return *min_element(all(a));
}
template<typename T, typename D>
D max(T a) {
return *max_element(all(a));
}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
#include "supertrees.h"
int construct(std::vector<std::vector<int>> p) {
int n = sz(p);
vi pp(n); iota(all(pp), 0);
rngi(i, n) rngi(j, n) if (p[i][j] > 2)return 0;
function<int(int)> get = [&](int x) {
if (x == pp[x])return x; return pp[x] = get(pp[x]);
};
auto mrg = [&](int x, int y) {
x = get(x); y = get(y);
if (x == y)return 0;
if (rand() & 1)swap(x, y); pp[x] = y; return 1;
};
auto same = [&](int x, int y) {return get(x) == get(y); };
rngi(i, n) for (int j = i + 1; j < n; j++) if (p[i][j]) mrg(i, j);
rngi(j, n) rngi(i, j) if (!p[i][j] && same(i, j)) return 0;
vector<vi> cmp(n); rngi(i, n) cmp[get(i)].push_back(i);
vector < vi > b(n, vi(n));
rngi(ii, n) {
vi c = cmp[ii];
int m = sz(c);
vi root(n, -1);
vi cr;
for (int x : c)if (root[x] == -1) {
root[x] = x; cr.push_back(x);
rngi(i, n) if (p[x][i] == 1 && x != i) {
root[i] = x;
b[i][x] = b[x][i] = 1;
}
}
if (sz(cr) == 2)return 0;
if(sz(cr) > 2)
rngi(i, sz(cr)) b[cr[i]][cr[(i + 1) % sz(cr)]] = b[cr[(i + 1) % sz(cr)]][cr[i]] = 1;
}
build(b);
return 1;
}
Compilation message
supertrees.cpp: In lambda function:
supertrees.cpp:119:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
119 | if (x == pp[x])return x; return pp[x] = get(pp[x]);
| ^~
supertrees.cpp:119:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
119 | if (x == pp[x])return x; return pp[x] = get(pp[x]);
| ^~~~~~
supertrees.cpp: In lambda function:
supertrees.cpp:124:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
124 | if (rand() & 1)swap(x, y); pp[x] = y; return 1;
| ^~
supertrees.cpp:124:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
124 | if (rand() & 1)swap(x, y); pp[x] = y; return 1;
| ^~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:133:13: warning: unused variable 'm' [-Wunused-variable]
133 | int m = sz(c);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
12 ms |
1260 KB |
Output is correct |
7 |
Correct |
254 ms |
22252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
12 ms |
1260 KB |
Output is correct |
7 |
Correct |
254 ms |
22252 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1388 KB |
Output is correct |
13 |
Correct |
249 ms |
22368 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
620 KB |
Output is correct |
17 |
Correct |
119 ms |
8172 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
65 ms |
5900 KB |
Output is correct |
21 |
Correct |
258 ms |
22252 KB |
Output is correct |
22 |
Correct |
261 ms |
22252 KB |
Output is correct |
23 |
Correct |
265 ms |
22124 KB |
Output is correct |
24 |
Correct |
251 ms |
22252 KB |
Output is correct |
25 |
Correct |
108 ms |
8172 KB |
Output is correct |
26 |
Correct |
105 ms |
8172 KB |
Output is correct |
27 |
Correct |
268 ms |
22252 KB |
Output is correct |
28 |
Correct |
257 ms |
22124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
268 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
11 ms |
1260 KB |
Output is correct |
9 |
Correct |
251 ms |
22124 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1176 KB |
Output is correct |
13 |
Correct |
256 ms |
22124 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
620 KB |
Output is correct |
17 |
Correct |
119 ms |
8172 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
65 ms |
5868 KB |
Output is correct |
22 |
Correct |
261 ms |
22124 KB |
Output is correct |
23 |
Correct |
258 ms |
22124 KB |
Output is correct |
24 |
Correct |
272 ms |
22252 KB |
Output is correct |
25 |
Correct |
114 ms |
12268 KB |
Output is correct |
26 |
Correct |
108 ms |
8160 KB |
Output is correct |
27 |
Correct |
257 ms |
22124 KB |
Output is correct |
28 |
Correct |
269 ms |
22252 KB |
Output is correct |
29 |
Correct |
112 ms |
12268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
65 ms |
5868 KB |
Output is correct |
5 |
Correct |
256 ms |
22124 KB |
Output is correct |
6 |
Correct |
255 ms |
22068 KB |
Output is correct |
7 |
Correct |
265 ms |
22252 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
67 ms |
5868 KB |
Output is correct |
10 |
Correct |
259 ms |
22124 KB |
Output is correct |
11 |
Correct |
253 ms |
22124 KB |
Output is correct |
12 |
Correct |
272 ms |
22176 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
67 ms |
5868 KB |
Output is correct |
17 |
Correct |
262 ms |
22124 KB |
Output is correct |
18 |
Correct |
257 ms |
22124 KB |
Output is correct |
19 |
Correct |
258 ms |
22252 KB |
Output is correct |
20 |
Correct |
247 ms |
22124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
12 ms |
1260 KB |
Output is correct |
7 |
Correct |
254 ms |
22252 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1388 KB |
Output is correct |
13 |
Correct |
249 ms |
22368 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
620 KB |
Output is correct |
17 |
Correct |
119 ms |
8172 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
65 ms |
5900 KB |
Output is correct |
21 |
Correct |
258 ms |
22252 KB |
Output is correct |
22 |
Correct |
261 ms |
22252 KB |
Output is correct |
23 |
Correct |
265 ms |
22124 KB |
Output is correct |
24 |
Correct |
251 ms |
22252 KB |
Output is correct |
25 |
Correct |
108 ms |
8172 KB |
Output is correct |
26 |
Correct |
105 ms |
8172 KB |
Output is correct |
27 |
Correct |
268 ms |
22252 KB |
Output is correct |
28 |
Correct |
257 ms |
22124 KB |
Output is correct |
29 |
Correct |
1 ms |
268 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
11 ms |
1260 KB |
Output is correct |
37 |
Correct |
251 ms |
22124 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
11 ms |
1176 KB |
Output is correct |
41 |
Correct |
256 ms |
22124 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
620 KB |
Output is correct |
45 |
Correct |
119 ms |
8172 KB |
Output is correct |
46 |
Correct |
0 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
0 ms |
364 KB |
Output is correct |
49 |
Correct |
65 ms |
5868 KB |
Output is correct |
50 |
Correct |
261 ms |
22124 KB |
Output is correct |
51 |
Correct |
258 ms |
22124 KB |
Output is correct |
52 |
Correct |
272 ms |
22252 KB |
Output is correct |
53 |
Correct |
114 ms |
12268 KB |
Output is correct |
54 |
Correct |
108 ms |
8160 KB |
Output is correct |
55 |
Correct |
257 ms |
22124 KB |
Output is correct |
56 |
Correct |
269 ms |
22252 KB |
Output is correct |
57 |
Correct |
112 ms |
12268 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
5 ms |
620 KB |
Output is correct |
61 |
Correct |
117 ms |
8172 KB |
Output is correct |
62 |
Correct |
1 ms |
364 KB |
Output is correct |
63 |
Correct |
1 ms |
364 KB |
Output is correct |
64 |
Correct |
1 ms |
364 KB |
Output is correct |
65 |
Correct |
64 ms |
5848 KB |
Output is correct |
66 |
Correct |
106 ms |
8172 KB |
Output is correct |
67 |
Correct |
106 ms |
8172 KB |
Output is correct |
68 |
Correct |
104 ms |
8172 KB |
Output is correct |
69 |
Correct |
116 ms |
12268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
12 ms |
1260 KB |
Output is correct |
7 |
Correct |
254 ms |
22252 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1388 KB |
Output is correct |
13 |
Correct |
249 ms |
22368 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
620 KB |
Output is correct |
17 |
Correct |
119 ms |
8172 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
65 ms |
5900 KB |
Output is correct |
21 |
Correct |
258 ms |
22252 KB |
Output is correct |
22 |
Correct |
261 ms |
22252 KB |
Output is correct |
23 |
Correct |
265 ms |
22124 KB |
Output is correct |
24 |
Correct |
251 ms |
22252 KB |
Output is correct |
25 |
Correct |
108 ms |
8172 KB |
Output is correct |
26 |
Correct |
105 ms |
8172 KB |
Output is correct |
27 |
Correct |
268 ms |
22252 KB |
Output is correct |
28 |
Correct |
257 ms |
22124 KB |
Output is correct |
29 |
Correct |
1 ms |
268 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
11 ms |
1260 KB |
Output is correct |
37 |
Correct |
251 ms |
22124 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
11 ms |
1176 KB |
Output is correct |
41 |
Correct |
256 ms |
22124 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
620 KB |
Output is correct |
45 |
Correct |
119 ms |
8172 KB |
Output is correct |
46 |
Correct |
0 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
0 ms |
364 KB |
Output is correct |
49 |
Correct |
65 ms |
5868 KB |
Output is correct |
50 |
Correct |
261 ms |
22124 KB |
Output is correct |
51 |
Correct |
258 ms |
22124 KB |
Output is correct |
52 |
Correct |
272 ms |
22252 KB |
Output is correct |
53 |
Correct |
114 ms |
12268 KB |
Output is correct |
54 |
Correct |
108 ms |
8160 KB |
Output is correct |
55 |
Correct |
257 ms |
22124 KB |
Output is correct |
56 |
Correct |
269 ms |
22252 KB |
Output is correct |
57 |
Correct |
112 ms |
12268 KB |
Output is correct |
58 |
Correct |
0 ms |
364 KB |
Output is correct |
59 |
Correct |
0 ms |
364 KB |
Output is correct |
60 |
Correct |
0 ms |
364 KB |
Output is correct |
61 |
Correct |
65 ms |
5868 KB |
Output is correct |
62 |
Correct |
256 ms |
22124 KB |
Output is correct |
63 |
Correct |
255 ms |
22068 KB |
Output is correct |
64 |
Correct |
265 ms |
22252 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
67 ms |
5868 KB |
Output is correct |
67 |
Correct |
259 ms |
22124 KB |
Output is correct |
68 |
Correct |
253 ms |
22124 KB |
Output is correct |
69 |
Correct |
272 ms |
22176 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
1 ms |
364 KB |
Output is correct |
73 |
Correct |
67 ms |
5868 KB |
Output is correct |
74 |
Correct |
262 ms |
22124 KB |
Output is correct |
75 |
Correct |
257 ms |
22124 KB |
Output is correct |
76 |
Correct |
258 ms |
22252 KB |
Output is correct |
77 |
Correct |
247 ms |
22124 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
1 ms |
364 KB |
Output is correct |
80 |
Correct |
5 ms |
620 KB |
Output is correct |
81 |
Correct |
117 ms |
8172 KB |
Output is correct |
82 |
Correct |
1 ms |
364 KB |
Output is correct |
83 |
Correct |
1 ms |
364 KB |
Output is correct |
84 |
Correct |
1 ms |
364 KB |
Output is correct |
85 |
Correct |
64 ms |
5848 KB |
Output is correct |
86 |
Correct |
106 ms |
8172 KB |
Output is correct |
87 |
Correct |
106 ms |
8172 KB |
Output is correct |
88 |
Correct |
104 ms |
8172 KB |
Output is correct |
89 |
Correct |
116 ms |
12268 KB |
Output is correct |
90 |
Correct |
1 ms |
364 KB |
Output is correct |
91 |
Correct |
1 ms |
364 KB |
Output is correct |
92 |
Correct |
7 ms |
620 KB |
Output is correct |
93 |
Correct |
104 ms |
8160 KB |
Output is correct |
94 |
Correct |
1 ms |
364 KB |
Output is correct |
95 |
Correct |
0 ms |
364 KB |
Output is correct |
96 |
Correct |
1 ms |
364 KB |
Output is correct |
97 |
Correct |
26 ms |
2284 KB |
Output is correct |
98 |
Correct |
104 ms |
8172 KB |
Output is correct |
99 |
Correct |
104 ms |
8172 KB |
Output is correct |
100 |
Correct |
104 ms |
8172 KB |
Output is correct |
101 |
Correct |
103 ms |
8172 KB |
Output is correct |
102 |
Correct |
101 ms |
8172 KB |
Output is correct |
103 |
Correct |
102 ms |
8172 KB |
Output is correct |
104 |
Correct |
102 ms |
8172 KB |
Output is correct |
105 |
Correct |
110 ms |
8172 KB |
Output is correct |