#include "supertrees.h"
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define FILER 0
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = pow(10, 9) + 7;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const ull INFUL = 0x3f3f3f3f3f3f3f3f;
const ll INFT = 0x3f3f3f3f;
const ull MAX = 1LL << 24;
const ll MODD = 998244353;
const double EPS = 1e-10;
#define V vector
#define pll pair<ll, ll>
#define pull2 pair<ull,ull>
#define MS multiset
#define M map
#define Q queue
#define PQ priority_queue
#define IOF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(typ,i,a,b,c) for(typ i = a; i < b; i += c)
#define FORR(typ,i,a,b,c) for(typ i = a; i > b; i -= c)
#define FORA(a,i) for(auto &i : a)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define sorta(a) sort(all(a))
#define sortd(a) sort(all(a), greater<ll>())
#define setp(x) setprecision(x)<<fixed
#define RET return
#define log(a,b) log(b)/log(a)
#define WH(s) while(s)
#define WHI(t) WH(t--)
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YESNO(s) cout << (s ? "YES" : "NO") << endl;
#define YesNo(s) cout<<(s?"Yes":"No")<<endl;
#define TYP 0
using namespace std;
struct dsu
{
V<ll> p, rnk;
ll n;
dsu(ll sz) :n(sz)
{
p.assign(n, 0);
iota(all(p), 0);
rnk.assign(n, 0);
}
void clear()
{
p.assign(n, 0);
iota(all(p), 0);
rnk.assign(n, 0);
}
ll find(ll u) { RET u == p[u] ? u : p[u] = find(p[u]); }
bool unite(ll u, ll v)
{
u = find(u), v = find(v);
if (u == v)RET 0;
if (rnk[u] < rnk[v]) swap(u, v);
p[v] = u, rnk[u]++;
RET 1;
}
};
ll n;
V<V<int>> p1, g, ans, g1;
V<int> chk2;
V<bool> us;
void dfs(ll u, ll p)
{
p1[u][p]++;
us[u] = 1;
FORA(g[u], v)
if (!us[v])dfs(v, p);
us[u] = 0;
}
int construct(std::vector<std::vector<int>> p)
{
n = p.size();
p1.resize(n, V<int>(n)); ans.resize(n, V<int>(n)); g.resize(n);
us.resize(n);
FOR(ll, i, 0, n, 1)
FOR(ll, j, 0, n, 1)
if (p[i][j] == 3) RET 0;
dsu dsu(n);
g1.assign(n, {});
FOR(ll, i, 0, n, 1)
FOR(ll, j, 0, n, 1)
if (p[i][j] == 1) dsu.unite(i, j);
FOR(ll, i, 0, n, 1) g1[dsu.find(i)].push_back(i);
FOR(ll, i, 0, n, 1)
{
if (g1[i].empty()) continue;
chk2.push_back(i);
ll sz = (g1[i].size() - 1);
FOR(ll, j, 0, sz, 1)
g[g1[i][j]].push_back(g1[i][j + 1]), g[g1[i][j + 1]].push_back(g1[i][j]), ans[g1[i][j]][g1[i][j + 1]] = ans[g1[i][j + 1]][g1[i][j]] = 1;
}
g1.assign(n, {});
dsu.clear();
FORA(chk2, u)
FORA(chk2, v)
if (p[u][v] == 2)dsu.unite(u, v);
FOR(ll, i, 0, n, 1) g1[dsu.find(i)].push_back(i);
FOR(ll, i, 0, n, 1)
{
//can't create cycle with 2 nodes
if (g1[i].size() <= 2)continue;
FOR(ll, j, 0, g1[i].size() - 1, 1)
g[g1[i][j]].push_back(g1[i][j + 1]), g[g1[i][j + 1]].push_back(g1[i][j]), ans[g1[i][j]][g1[i][j + 1]] = ans[g1[i][j + 1]][g1[i][j]] = 1;
g[g1[i].back()].push_back(g1[i][0]), g[g1[i][0]].push_back(g1[i].back());
ans[g1[i].back()][g1[i][0]] = ans[g1[i][0]][g1[i].back()] = 1;
}
FOR(ll, u, 0, n, 1)
dfs(u, u);
FOR(ll, i, 0, n, 1)FOR(ll, j, 0, n, 1)if (p1[i][j] != p[i][j])RET 0;
build(ans);
RET 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:24:43: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | #define FOR(typ,i,a,b,c) for(typ i = a; i < b; i += c)
......
115 | FOR(ll, j, 0, g1[i].size() - 1, 1)
| ~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:115:3: note: in expansion of macro 'FOR'
115 | FOR(ll, j, 0, g1[i].size() - 1, 1)
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
160 ms |
27472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
160 ms |
27472 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
150 ms |
27288 KB |
Output is correct |
14 |
Correct |
1 ms |
444 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
960 KB |
Output is correct |
17 |
Correct |
82 ms |
17492 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
38 ms |
7252 KB |
Output is correct |
21 |
Correct |
148 ms |
27472 KB |
Output is correct |
22 |
Correct |
145 ms |
27400 KB |
Output is correct |
23 |
Correct |
157 ms |
27528 KB |
Output is correct |
24 |
Correct |
171 ms |
27480 KB |
Output is correct |
25 |
Correct |
66 ms |
17528 KB |
Output is correct |
26 |
Correct |
62 ms |
17496 KB |
Output is correct |
27 |
Correct |
157 ms |
27476 KB |
Output is correct |
28 |
Correct |
151 ms |
27488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
1372 KB |
Output is correct |
9 |
Correct |
150 ms |
28244 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1448 KB |
Output is correct |
13 |
Correct |
169 ms |
28096 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
6 ms |
1112 KB |
Output is correct |
17 |
Correct |
92 ms |
18312 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
38 ms |
7256 KB |
Output is correct |
22 |
Correct |
157 ms |
27988 KB |
Output is correct |
23 |
Correct |
146 ms |
27984 KB |
Output is correct |
24 |
Correct |
168 ms |
28244 KB |
Output is correct |
25 |
Correct |
65 ms |
18260 KB |
Output is correct |
26 |
Correct |
68 ms |
18308 KB |
Output is correct |
27 |
Correct |
158 ms |
28128 KB |
Output is correct |
28 |
Correct |
165 ms |
28412 KB |
Output is correct |
29 |
Correct |
66 ms |
18184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
38 ms |
7300 KB |
Output is correct |
5 |
Correct |
149 ms |
28168 KB |
Output is correct |
6 |
Correct |
148 ms |
28036 KB |
Output is correct |
7 |
Correct |
159 ms |
28188 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
39 ms |
7296 KB |
Output is correct |
10 |
Correct |
152 ms |
28164 KB |
Output is correct |
11 |
Correct |
148 ms |
27988 KB |
Output is correct |
12 |
Correct |
164 ms |
28196 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
38 ms |
7260 KB |
Output is correct |
17 |
Correct |
169 ms |
28092 KB |
Output is correct |
18 |
Correct |
150 ms |
27984 KB |
Output is correct |
19 |
Correct |
156 ms |
28252 KB |
Output is correct |
20 |
Correct |
146 ms |
27984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
160 ms |
27472 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
150 ms |
27288 KB |
Output is correct |
14 |
Correct |
1 ms |
444 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
960 KB |
Output is correct |
17 |
Correct |
82 ms |
17492 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
38 ms |
7252 KB |
Output is correct |
21 |
Correct |
148 ms |
27472 KB |
Output is correct |
22 |
Correct |
145 ms |
27400 KB |
Output is correct |
23 |
Correct |
157 ms |
27528 KB |
Output is correct |
24 |
Correct |
171 ms |
27480 KB |
Output is correct |
25 |
Correct |
66 ms |
17528 KB |
Output is correct |
26 |
Correct |
62 ms |
17496 KB |
Output is correct |
27 |
Correct |
157 ms |
27476 KB |
Output is correct |
28 |
Correct |
151 ms |
27488 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
1372 KB |
Output is correct |
37 |
Correct |
150 ms |
28244 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1448 KB |
Output is correct |
41 |
Correct |
169 ms |
28096 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
6 ms |
1112 KB |
Output is correct |
45 |
Correct |
92 ms |
18312 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
38 ms |
7256 KB |
Output is correct |
50 |
Correct |
157 ms |
27988 KB |
Output is correct |
51 |
Correct |
146 ms |
27984 KB |
Output is correct |
52 |
Correct |
168 ms |
28244 KB |
Output is correct |
53 |
Correct |
65 ms |
18260 KB |
Output is correct |
54 |
Correct |
68 ms |
18308 KB |
Output is correct |
55 |
Correct |
158 ms |
28128 KB |
Output is correct |
56 |
Correct |
165 ms |
28412 KB |
Output is correct |
57 |
Correct |
66 ms |
18184 KB |
Output is correct |
58 |
Correct |
1 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
4 ms |
1112 KB |
Output is correct |
61 |
Correct |
87 ms |
18344 KB |
Output is correct |
62 |
Correct |
1 ms |
348 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
1 ms |
432 KB |
Output is correct |
65 |
Correct |
37 ms |
7296 KB |
Output is correct |
66 |
Correct |
73 ms |
18296 KB |
Output is correct |
67 |
Correct |
72 ms |
18308 KB |
Output is correct |
68 |
Correct |
64 ms |
18256 KB |
Output is correct |
69 |
Correct |
63 ms |
18188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
160 ms |
27472 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
150 ms |
27288 KB |
Output is correct |
14 |
Correct |
1 ms |
444 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
960 KB |
Output is correct |
17 |
Correct |
82 ms |
17492 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
38 ms |
7252 KB |
Output is correct |
21 |
Correct |
148 ms |
27472 KB |
Output is correct |
22 |
Correct |
145 ms |
27400 KB |
Output is correct |
23 |
Correct |
157 ms |
27528 KB |
Output is correct |
24 |
Correct |
171 ms |
27480 KB |
Output is correct |
25 |
Correct |
66 ms |
17528 KB |
Output is correct |
26 |
Correct |
62 ms |
17496 KB |
Output is correct |
27 |
Correct |
157 ms |
27476 KB |
Output is correct |
28 |
Correct |
151 ms |
27488 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
1372 KB |
Output is correct |
37 |
Correct |
150 ms |
28244 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1448 KB |
Output is correct |
41 |
Correct |
169 ms |
28096 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
6 ms |
1112 KB |
Output is correct |
45 |
Correct |
92 ms |
18312 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
38 ms |
7256 KB |
Output is correct |
50 |
Correct |
157 ms |
27988 KB |
Output is correct |
51 |
Correct |
146 ms |
27984 KB |
Output is correct |
52 |
Correct |
168 ms |
28244 KB |
Output is correct |
53 |
Correct |
65 ms |
18260 KB |
Output is correct |
54 |
Correct |
68 ms |
18308 KB |
Output is correct |
55 |
Correct |
158 ms |
28128 KB |
Output is correct |
56 |
Correct |
165 ms |
28412 KB |
Output is correct |
57 |
Correct |
66 ms |
18184 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
38 ms |
7300 KB |
Output is correct |
62 |
Correct |
149 ms |
28168 KB |
Output is correct |
63 |
Correct |
148 ms |
28036 KB |
Output is correct |
64 |
Correct |
159 ms |
28188 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
39 ms |
7296 KB |
Output is correct |
67 |
Correct |
152 ms |
28164 KB |
Output is correct |
68 |
Correct |
148 ms |
27988 KB |
Output is correct |
69 |
Correct |
164 ms |
28196 KB |
Output is correct |
70 |
Correct |
0 ms |
348 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
344 KB |
Output is correct |
73 |
Correct |
38 ms |
7260 KB |
Output is correct |
74 |
Correct |
169 ms |
28092 KB |
Output is correct |
75 |
Correct |
150 ms |
27984 KB |
Output is correct |
76 |
Correct |
156 ms |
28252 KB |
Output is correct |
77 |
Correct |
146 ms |
27984 KB |
Output is correct |
78 |
Correct |
1 ms |
344 KB |
Output is correct |
79 |
Correct |
0 ms |
348 KB |
Output is correct |
80 |
Correct |
4 ms |
1112 KB |
Output is correct |
81 |
Correct |
87 ms |
18344 KB |
Output is correct |
82 |
Correct |
1 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
1 ms |
432 KB |
Output is correct |
85 |
Correct |
37 ms |
7296 KB |
Output is correct |
86 |
Correct |
73 ms |
18296 KB |
Output is correct |
87 |
Correct |
72 ms |
18308 KB |
Output is correct |
88 |
Correct |
64 ms |
18256 KB |
Output is correct |
89 |
Correct |
63 ms |
18188 KB |
Output is correct |
90 |
Correct |
1 ms |
344 KB |
Output is correct |
91 |
Correct |
0 ms |
344 KB |
Output is correct |
92 |
Correct |
3 ms |
956 KB |
Output is correct |
93 |
Correct |
67 ms |
18052 KB |
Output is correct |
94 |
Correct |
1 ms |
348 KB |
Output is correct |
95 |
Correct |
0 ms |
344 KB |
Output is correct |
96 |
Correct |
1 ms |
392 KB |
Output is correct |
97 |
Correct |
16 ms |
4700 KB |
Output is correct |
98 |
Correct |
65 ms |
18188 KB |
Output is correct |
99 |
Correct |
62 ms |
18004 KB |
Output is correct |
100 |
Correct |
72 ms |
18128 KB |
Output is correct |
101 |
Correct |
63 ms |
18168 KB |
Output is correct |
102 |
Correct |
81 ms |
18000 KB |
Output is correct |
103 |
Correct |
64 ms |
18036 KB |
Output is correct |
104 |
Correct |
63 ms |
18288 KB |
Output is correct |
105 |
Correct |
65 ms |
18180 KB |
Output is correct |