// supertree.yml
#include "bits/stdc++.h"
using namespace std;
// Defines
#define fs first
#define sn second
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
// Basic type definitions
using ll = long long; using ull = unsigned long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<long long, long long>;
// PBDS order statistic tree
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T, class comp = less<T>> using os_tree = tree<T, null_type, comp, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V, class comp = less<K>> using treemap = tree<K, V, comp, rb_tree_tag, tree_order_statistics_node_update>;
// HashSet
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash { ll operator()(ll x) const { return x ^ RANDOM; } };
template <typename T, class Hash> using hashset = gp_hash_table<T, null_type, Hash>;
template <typename K, typename V, class Hash> using hashmap = gp_hash_table<K, V, Hash>;
// More utilities
int SZ(string &v) { return v.length(); }
template <typename C> int SZ(C &v) { return v.size(); }
template <typename C> void UNIQUE(vector<C> &v) { sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); }
template <typename T, typename U> void maxa(T &a, U b) { a = max(a, b); }
template <typename T, typename U> void mina(T &a, U b) { a = min(a, b); }
const ll INF = 0x3f3f3f3f, LLINF = 0x3f3f3f3f3f3f3f3f;
struct DSU {
vector<int> dsu;
void init(int N) {
dsu.resize(N + 1);
iota(dsu.begin(), dsu.end(), 0);
}
int rt(int x) { return dsu[x] == x ? x : dsu[x] = rt(dsu[x]); }
void merge(int x, int y) { // x -> y
dsu[rt(x)] = rt(y); }
bool same(int x, int y) { return rt(x) == rt(y); }
};
void build(vector<vector<int>> v);
int construct(vector<vector<int>> g) {
int N = SZ(g);
vector<vector<int>> ansg(N, vector<int>(N));
DSU d; d.init(N);
for (auto i = 0; i < N; i++) {
for (auto j = 0; j < N; j++) {
if (g[i][j])
d.merge(i, j);
// symmetrical
if (g[i][j] != g[j][i]) return 0;
// impossible if 3
if (g[i][j] == 3) return 0;
}
}
vector<vector<int>> comp(N);
for (auto i = 0; i < N; i++)
comp[d.rt(i)].pb(i);
auto _A = [&] (int x, int y) -> void {
ansg[x][y] = ansg[y][x] = true;
};
// with components
for (auto i = 0; i < N; i++) {
if (!comp[i].empty()) {
auto &cc = comp[i];
// cout<<"i="<<(i)<<", "; cout << "cc=["; for (auto __x:cc)cout<<__x<<", "; cout<<"], "; cout << endl; // db i,I:cc
if (SZ(cc) == 1) continue;
for (auto x : cc)
for (auto y : cc)
if (!g[x][y] || !g[y][x])
return 0;
DSU dd; dd.init(N);
for (auto x : cc)
for (auto y : cc)
if (g[x][y] == 1)
dd.merge(x, y);
vector<vector<int>> ccomp(N);
vector<int> roots;
for (auto x : cc) {
ccomp[dd.rt(x)].pb(x);
roots.pb(dd.rt(x));
}
UNIQUE(roots);
// check
for (auto x : cc)
for (auto y : cc)
if ((g[x][y] == 1) != dd.same(x, y))
return 0;
// build graph
if (SZ(roots) >= 2) {
if (SZ(roots) == 2) return 0;
for (auto i = 0; i < SZ(roots); i++)
_A(roots[i], roots[(i + 1) % SZ(roots)]);
}
for (auto x : cc) {
if (!ccomp[x].empty()) {
for (auto j = 0; j < SZ(ccomp[x])-1; j++)
_A(ccomp[x][j], ccomp[x][j + 1]);
}
}
}
}
build(ansg);
return 1;
}
#ifdef LOCAL
int N;
vector<vector<int>> req, ans;
void build(vector<vector<int>> v) { ans = v; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> (N);
req.assign(N, vector<int>(N));
for (auto i = 0; i < N; i++)
for (auto j = 0; j < N; j++)
cin >> (req[i][j]);
int correct;
cin >> correct;
int out = construct(req);
cout<<"out="<<(out)<<", "; cout<<"correct="<<(correct)<<", "; cout << endl; // db out,correct
if (out) {
cout << "Graph:" << endl;
for (auto i = 0; i < N; i++)
for (auto j = i; j < N; j++)
if (ans[i][j])
cout << (i) << ' ' << (j) << '\n';
}
return 0;
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
1280 KB |
Output is correct |
7 |
Correct |
283 ms |
22100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
1280 KB |
Output is correct |
7 |
Correct |
283 ms |
22100 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1152 KB |
Output is correct |
13 |
Correct |
250 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
768 KB |
Output is correct |
17 |
Correct |
130 ms |
12152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
64 ms |
5880 KB |
Output is correct |
21 |
Correct |
256 ms |
22264 KB |
Output is correct |
22 |
Correct |
250 ms |
22136 KB |
Output is correct |
23 |
Correct |
284 ms |
22136 KB |
Output is correct |
24 |
Correct |
249 ms |
22360 KB |
Output is correct |
25 |
Correct |
114 ms |
12152 KB |
Output is correct |
26 |
Correct |
108 ms |
12280 KB |
Output is correct |
27 |
Correct |
279 ms |
22136 KB |
Output is correct |
28 |
Correct |
246 ms |
22136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
11 ms |
1280 KB |
Output is correct |
9 |
Correct |
250 ms |
22104 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
12 ms |
1152 KB |
Output is correct |
13 |
Correct |
273 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
7 ms |
768 KB |
Output is correct |
17 |
Correct |
132 ms |
12152 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
63 ms |
6008 KB |
Output is correct |
22 |
Correct |
258 ms |
22136 KB |
Output is correct |
23 |
Correct |
248 ms |
22136 KB |
Output is correct |
24 |
Correct |
273 ms |
22136 KB |
Output is correct |
25 |
Correct |
103 ms |
12280 KB |
Output is correct |
26 |
Correct |
111 ms |
12152 KB |
Output is correct |
27 |
Correct |
246 ms |
22136 KB |
Output is correct |
28 |
Correct |
275 ms |
22136 KB |
Output is correct |
29 |
Correct |
108 ms |
12280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
65 ms |
5880 KB |
Output is correct |
5 |
Correct |
256 ms |
22136 KB |
Output is correct |
6 |
Correct |
248 ms |
22100 KB |
Output is correct |
7 |
Correct |
278 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
64 ms |
5884 KB |
Output is correct |
10 |
Correct |
250 ms |
22156 KB |
Output is correct |
11 |
Correct |
243 ms |
22100 KB |
Output is correct |
12 |
Correct |
273 ms |
22100 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
64 ms |
5880 KB |
Output is correct |
17 |
Correct |
252 ms |
22136 KB |
Output is correct |
18 |
Correct |
256 ms |
22136 KB |
Output is correct |
19 |
Correct |
247 ms |
22136 KB |
Output is correct |
20 |
Correct |
242 ms |
22136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
1280 KB |
Output is correct |
7 |
Correct |
283 ms |
22100 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1152 KB |
Output is correct |
13 |
Correct |
250 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
768 KB |
Output is correct |
17 |
Correct |
130 ms |
12152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
64 ms |
5880 KB |
Output is correct |
21 |
Correct |
256 ms |
22264 KB |
Output is correct |
22 |
Correct |
250 ms |
22136 KB |
Output is correct |
23 |
Correct |
284 ms |
22136 KB |
Output is correct |
24 |
Correct |
249 ms |
22360 KB |
Output is correct |
25 |
Correct |
114 ms |
12152 KB |
Output is correct |
26 |
Correct |
108 ms |
12280 KB |
Output is correct |
27 |
Correct |
279 ms |
22136 KB |
Output is correct |
28 |
Correct |
246 ms |
22136 KB |
Output is correct |
29 |
Correct |
1 ms |
256 KB |
Output is correct |
30 |
Correct |
1 ms |
256 KB |
Output is correct |
31 |
Correct |
1 ms |
256 KB |
Output is correct |
32 |
Correct |
0 ms |
256 KB |
Output is correct |
33 |
Correct |
1 ms |
256 KB |
Output is correct |
34 |
Correct |
1 ms |
256 KB |
Output is correct |
35 |
Correct |
1 ms |
256 KB |
Output is correct |
36 |
Correct |
11 ms |
1280 KB |
Output is correct |
37 |
Correct |
250 ms |
22104 KB |
Output is correct |
38 |
Correct |
1 ms |
256 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
12 ms |
1152 KB |
Output is correct |
41 |
Correct |
273 ms |
22136 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
0 ms |
256 KB |
Output is correct |
44 |
Correct |
7 ms |
768 KB |
Output is correct |
45 |
Correct |
132 ms |
12152 KB |
Output is correct |
46 |
Correct |
0 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
63 ms |
6008 KB |
Output is correct |
50 |
Correct |
258 ms |
22136 KB |
Output is correct |
51 |
Correct |
248 ms |
22136 KB |
Output is correct |
52 |
Correct |
273 ms |
22136 KB |
Output is correct |
53 |
Correct |
103 ms |
12280 KB |
Output is correct |
54 |
Correct |
111 ms |
12152 KB |
Output is correct |
55 |
Correct |
246 ms |
22136 KB |
Output is correct |
56 |
Correct |
275 ms |
22136 KB |
Output is correct |
57 |
Correct |
108 ms |
12280 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
1 ms |
256 KB |
Output is correct |
60 |
Correct |
6 ms |
768 KB |
Output is correct |
61 |
Correct |
134 ms |
12248 KB |
Output is correct |
62 |
Correct |
0 ms |
256 KB |
Output is correct |
63 |
Correct |
1 ms |
384 KB |
Output is correct |
64 |
Correct |
1 ms |
256 KB |
Output is correct |
65 |
Correct |
62 ms |
5880 KB |
Output is correct |
66 |
Correct |
112 ms |
12152 KB |
Output is correct |
67 |
Correct |
114 ms |
12152 KB |
Output is correct |
68 |
Correct |
107 ms |
12152 KB |
Output is correct |
69 |
Correct |
109 ms |
12248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
1280 KB |
Output is correct |
7 |
Correct |
283 ms |
22100 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1152 KB |
Output is correct |
13 |
Correct |
250 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
768 KB |
Output is correct |
17 |
Correct |
130 ms |
12152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
64 ms |
5880 KB |
Output is correct |
21 |
Correct |
256 ms |
22264 KB |
Output is correct |
22 |
Correct |
250 ms |
22136 KB |
Output is correct |
23 |
Correct |
284 ms |
22136 KB |
Output is correct |
24 |
Correct |
249 ms |
22360 KB |
Output is correct |
25 |
Correct |
114 ms |
12152 KB |
Output is correct |
26 |
Correct |
108 ms |
12280 KB |
Output is correct |
27 |
Correct |
279 ms |
22136 KB |
Output is correct |
28 |
Correct |
246 ms |
22136 KB |
Output is correct |
29 |
Correct |
1 ms |
256 KB |
Output is correct |
30 |
Correct |
1 ms |
256 KB |
Output is correct |
31 |
Correct |
1 ms |
256 KB |
Output is correct |
32 |
Correct |
0 ms |
256 KB |
Output is correct |
33 |
Correct |
1 ms |
256 KB |
Output is correct |
34 |
Correct |
1 ms |
256 KB |
Output is correct |
35 |
Correct |
1 ms |
256 KB |
Output is correct |
36 |
Correct |
11 ms |
1280 KB |
Output is correct |
37 |
Correct |
250 ms |
22104 KB |
Output is correct |
38 |
Correct |
1 ms |
256 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
12 ms |
1152 KB |
Output is correct |
41 |
Correct |
273 ms |
22136 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
0 ms |
256 KB |
Output is correct |
44 |
Correct |
7 ms |
768 KB |
Output is correct |
45 |
Correct |
132 ms |
12152 KB |
Output is correct |
46 |
Correct |
0 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
63 ms |
6008 KB |
Output is correct |
50 |
Correct |
258 ms |
22136 KB |
Output is correct |
51 |
Correct |
248 ms |
22136 KB |
Output is correct |
52 |
Correct |
273 ms |
22136 KB |
Output is correct |
53 |
Correct |
103 ms |
12280 KB |
Output is correct |
54 |
Correct |
111 ms |
12152 KB |
Output is correct |
55 |
Correct |
246 ms |
22136 KB |
Output is correct |
56 |
Correct |
275 ms |
22136 KB |
Output is correct |
57 |
Correct |
108 ms |
12280 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
1 ms |
256 KB |
Output is correct |
60 |
Correct |
1 ms |
256 KB |
Output is correct |
61 |
Correct |
65 ms |
5880 KB |
Output is correct |
62 |
Correct |
256 ms |
22136 KB |
Output is correct |
63 |
Correct |
248 ms |
22100 KB |
Output is correct |
64 |
Correct |
278 ms |
22136 KB |
Output is correct |
65 |
Correct |
1 ms |
256 KB |
Output is correct |
66 |
Correct |
64 ms |
5884 KB |
Output is correct |
67 |
Correct |
250 ms |
22156 KB |
Output is correct |
68 |
Correct |
243 ms |
22100 KB |
Output is correct |
69 |
Correct |
273 ms |
22100 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
1 ms |
256 KB |
Output is correct |
72 |
Correct |
1 ms |
256 KB |
Output is correct |
73 |
Correct |
64 ms |
5880 KB |
Output is correct |
74 |
Correct |
252 ms |
22136 KB |
Output is correct |
75 |
Correct |
256 ms |
22136 KB |
Output is correct |
76 |
Correct |
247 ms |
22136 KB |
Output is correct |
77 |
Correct |
242 ms |
22136 KB |
Output is correct |
78 |
Correct |
1 ms |
256 KB |
Output is correct |
79 |
Correct |
1 ms |
256 KB |
Output is correct |
80 |
Correct |
6 ms |
768 KB |
Output is correct |
81 |
Correct |
134 ms |
12248 KB |
Output is correct |
82 |
Correct |
0 ms |
256 KB |
Output is correct |
83 |
Correct |
1 ms |
384 KB |
Output is correct |
84 |
Correct |
1 ms |
256 KB |
Output is correct |
85 |
Correct |
62 ms |
5880 KB |
Output is correct |
86 |
Correct |
112 ms |
12152 KB |
Output is correct |
87 |
Correct |
114 ms |
12152 KB |
Output is correct |
88 |
Correct |
107 ms |
12152 KB |
Output is correct |
89 |
Correct |
109 ms |
12248 KB |
Output is correct |
90 |
Correct |
0 ms |
256 KB |
Output is correct |
91 |
Correct |
1 ms |
256 KB |
Output is correct |
92 |
Correct |
5 ms |
768 KB |
Output is correct |
93 |
Correct |
124 ms |
12116 KB |
Output is correct |
94 |
Correct |
1 ms |
256 KB |
Output is correct |
95 |
Correct |
1 ms |
256 KB |
Output is correct |
96 |
Correct |
0 ms |
256 KB |
Output is correct |
97 |
Correct |
26 ms |
3328 KB |
Output is correct |
98 |
Correct |
106 ms |
12152 KB |
Output is correct |
99 |
Correct |
111 ms |
12280 KB |
Output is correct |
100 |
Correct |
104 ms |
12152 KB |
Output is correct |
101 |
Correct |
101 ms |
12152 KB |
Output is correct |
102 |
Correct |
120 ms |
12124 KB |
Output is correct |
103 |
Correct |
120 ms |
12152 KB |
Output is correct |
104 |
Correct |
121 ms |
12116 KB |
Output is correct |
105 |
Correct |
124 ms |
12156 KB |
Output is correct |