#include<bits/stdc++.h>
#include"supertrees.h"
#define rep(i,a,b) for(int i=a;i<int(b);i++)
#define rrep(i,a,b)for(int i=a;i>int(b);i--)
#define all(v) v.begin(),v.end()
#define trav(a,v) for(auto& a: v)
typedef long long ll;
using namespace std;
const long long inf = 1e15;
vector<ll> p(2001);
vector<ll> Rank(2001);
ll Ufindset(ll i) {
if (p[i] == i)return i;
return p[i] = Ufindset(p[i]);
}
void UjoinSet(ll i, ll j) {
ll si = Ufindset(i);
ll sj = Ufindset(j);
if (sj == si)return;
if (Rank[sj] > Rank[si])swap(sj, si);
p[sj] = si;
if (Rank[sj] == Rank[si]) Rank[si]++;
}
void print(vector<ll> v) {
trav(a, v)cout << a << " ";
cout << endl;
}
int construct(vector<vector<int>> v) {
rep(i, 0, 2001)p[i] = i;
vector<vector<int>> b(v.size(), vector<int>(v.size()));
rep(i, 0, v.size()) {
ll root = p[i];
ll last = i;
ll two = 0;
rep(j, 0, v.size()) {
if (v[i][j] == 3)return 0;
if (v[i][j]) {
if (v[i][j] == 2) {
p[p[i]] = i;
p[i] = i;
two++;
}
else if (v[i][j] == 1)UjoinSet(i, j);
}
}
}
rep(i, 0, v.size()) Ufindset(i);
rep(i, 0, v.size()) {
ll last = i;
rep(j, 0, v.size()) {
if (i == j)continue;
if (v[i][j]) {
if (v[i][j]==1) {
if (p[i] == i) {
UjoinSet(last, j);
b[last][j] = 1;
b[j][last] = 1;
}
last = j;
}
}
}
}
rep(i, 0, v.size()) {
ll last = i;
ll two = 0;
rep(j, 0, v.size()) {
Ufindset(j);
if (i == j)continue;
if (v[i][j]) {
if (p[j] != j) {
if (p[j] != p[i]) {
if (v[p[i]][p[j]] != v[i][j])return 0;
}
}
}
else if (p[j] == p[i]) return 0;
if (p[i] == i) {
if (p[j] == j) {
if (v[i][j] == 2) {
two++;
UjoinSet(last, j);
b[last][j] = 1;
b[j][last] = 1;
last = j;
}
}
}
}
if (p[i]==i&&two) {
if (two == 1)return 0;
if (p[i] == i) {
UjoinSet(last, i);
b[last][i] = 1;
b[i][last] = 1;
}
}
}
build(b);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:33:6: warning: unused variable 'root' [-Wunused-variable]
33 | ll root = p[i];
| ^~~~
supertrees.cpp:34:6: warning: unused variable 'last' [-Wunused-variable]
34 | ll last = i;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
1100 KB |
Output is correct |
7 |
Correct |
293 ms |
22044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1100 KB |
Output is correct |
7 |
Correct |
293 ms |
22044 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 |
10 ms |
1100 KB |
Output is correct |
13 |
Correct |
253 ms |
21964 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
27 ms |
748 KB |
Output is correct |
17 |
Correct |
131 ms |
12076 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
97 ms |
5720 KB |
Output is correct |
21 |
Correct |
259 ms |
22084 KB |
Output is correct |
22 |
Correct |
256 ms |
22076 KB |
Output is correct |
23 |
Correct |
278 ms |
22008 KB |
Output is correct |
24 |
Correct |
245 ms |
21956 KB |
Output is correct |
25 |
Correct |
125 ms |
12100 KB |
Output is correct |
26 |
Correct |
106 ms |
12064 KB |
Output is correct |
27 |
Correct |
289 ms |
22060 KB |
Output is correct |
28 |
Correct |
254 ms |
22044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
11 ms |
1144 KB |
Output is correct |
9 |
Correct |
245 ms |
22044 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 |
1100 KB |
Output is correct |
13 |
Correct |
259 ms |
21956 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 |
130 ms |
12080 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 |
65 ms |
5668 KB |
Output is correct |
22 |
Correct |
254 ms |
22056 KB |
Output is correct |
23 |
Correct |
260 ms |
22044 KB |
Output is correct |
24 |
Correct |
291 ms |
21996 KB |
Output is correct |
25 |
Correct |
107 ms |
12060 KB |
Output is correct |
26 |
Correct |
110 ms |
12064 KB |
Output is correct |
27 |
Correct |
335 ms |
22100 KB |
Output is correct |
28 |
Correct |
269 ms |
21956 KB |
Output is correct |
29 |
Correct |
109 ms |
12064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
65 ms |
5792 KB |
Output is correct |
5 |
Correct |
262 ms |
21992 KB |
Output is correct |
6 |
Correct |
254 ms |
21956 KB |
Output is correct |
7 |
Correct |
276 ms |
21956 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
69 ms |
5776 KB |
Output is correct |
10 |
Correct |
252 ms |
22056 KB |
Output is correct |
11 |
Correct |
361 ms |
22100 KB |
Output is correct |
12 |
Correct |
274 ms |
22044 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 |
332 KB |
Output is correct |
16 |
Correct |
63 ms |
5792 KB |
Output is correct |
17 |
Correct |
255 ms |
22048 KB |
Output is correct |
18 |
Correct |
253 ms |
22052 KB |
Output is correct |
19 |
Correct |
253 ms |
22016 KB |
Output is correct |
20 |
Correct |
249 ms |
21960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1100 KB |
Output is correct |
7 |
Correct |
293 ms |
22044 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 |
10 ms |
1100 KB |
Output is correct |
13 |
Correct |
253 ms |
21964 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
27 ms |
748 KB |
Output is correct |
17 |
Correct |
131 ms |
12076 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
97 ms |
5720 KB |
Output is correct |
21 |
Correct |
259 ms |
22084 KB |
Output is correct |
22 |
Correct |
256 ms |
22076 KB |
Output is correct |
23 |
Correct |
278 ms |
22008 KB |
Output is correct |
24 |
Correct |
245 ms |
21956 KB |
Output is correct |
25 |
Correct |
125 ms |
12100 KB |
Output is correct |
26 |
Correct |
106 ms |
12064 KB |
Output is correct |
27 |
Correct |
289 ms |
22060 KB |
Output is correct |
28 |
Correct |
254 ms |
22044 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 |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
11 ms |
1144 KB |
Output is correct |
37 |
Correct |
245 ms |
22044 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 |
1100 KB |
Output is correct |
41 |
Correct |
259 ms |
21956 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
716 KB |
Output is correct |
45 |
Correct |
130 ms |
12080 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 |
65 ms |
5668 KB |
Output is correct |
50 |
Correct |
254 ms |
22056 KB |
Output is correct |
51 |
Correct |
260 ms |
22044 KB |
Output is correct |
52 |
Correct |
291 ms |
21996 KB |
Output is correct |
53 |
Correct |
107 ms |
12060 KB |
Output is correct |
54 |
Correct |
110 ms |
12064 KB |
Output is correct |
55 |
Correct |
335 ms |
22100 KB |
Output is correct |
56 |
Correct |
269 ms |
21956 KB |
Output is correct |
57 |
Correct |
109 ms |
12064 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
6 ms |
716 KB |
Output is correct |
61 |
Correct |
126 ms |
12060 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 |
208 KB |
Output is correct |
65 |
Incorrect |
27 ms |
3232 KB |
Answer gives possible 0 while actual possible 1 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1100 KB |
Output is correct |
7 |
Correct |
293 ms |
22044 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 |
10 ms |
1100 KB |
Output is correct |
13 |
Correct |
253 ms |
21964 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
27 ms |
748 KB |
Output is correct |
17 |
Correct |
131 ms |
12076 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
97 ms |
5720 KB |
Output is correct |
21 |
Correct |
259 ms |
22084 KB |
Output is correct |
22 |
Correct |
256 ms |
22076 KB |
Output is correct |
23 |
Correct |
278 ms |
22008 KB |
Output is correct |
24 |
Correct |
245 ms |
21956 KB |
Output is correct |
25 |
Correct |
125 ms |
12100 KB |
Output is correct |
26 |
Correct |
106 ms |
12064 KB |
Output is correct |
27 |
Correct |
289 ms |
22060 KB |
Output is correct |
28 |
Correct |
254 ms |
22044 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 |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
11 ms |
1144 KB |
Output is correct |
37 |
Correct |
245 ms |
22044 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 |
1100 KB |
Output is correct |
41 |
Correct |
259 ms |
21956 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
716 KB |
Output is correct |
45 |
Correct |
130 ms |
12080 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 |
65 ms |
5668 KB |
Output is correct |
50 |
Correct |
254 ms |
22056 KB |
Output is correct |
51 |
Correct |
260 ms |
22044 KB |
Output is correct |
52 |
Correct |
291 ms |
21996 KB |
Output is correct |
53 |
Correct |
107 ms |
12060 KB |
Output is correct |
54 |
Correct |
110 ms |
12064 KB |
Output is correct |
55 |
Correct |
335 ms |
22100 KB |
Output is correct |
56 |
Correct |
269 ms |
21956 KB |
Output is correct |
57 |
Correct |
109 ms |
12064 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
65 ms |
5792 KB |
Output is correct |
62 |
Correct |
262 ms |
21992 KB |
Output is correct |
63 |
Correct |
254 ms |
21956 KB |
Output is correct |
64 |
Correct |
276 ms |
21956 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
69 ms |
5776 KB |
Output is correct |
67 |
Correct |
252 ms |
22056 KB |
Output is correct |
68 |
Correct |
361 ms |
22100 KB |
Output is correct |
69 |
Correct |
274 ms |
22044 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 |
332 KB |
Output is correct |
73 |
Correct |
63 ms |
5792 KB |
Output is correct |
74 |
Correct |
255 ms |
22048 KB |
Output is correct |
75 |
Correct |
253 ms |
22052 KB |
Output is correct |
76 |
Correct |
253 ms |
22016 KB |
Output is correct |
77 |
Correct |
249 ms |
21960 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
1 ms |
204 KB |
Output is correct |
80 |
Correct |
6 ms |
716 KB |
Output is correct |
81 |
Correct |
126 ms |
12060 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 |
208 KB |
Output is correct |
85 |
Incorrect |
27 ms |
3232 KB |
Answer gives possible 0 while actual possible 1 |
86 |
Halted |
0 ms |
0 KB |
- |