#include "supertrees.h"
#include <cassert>
#include <map>
#include <vector>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define ln "\n"
#define pll pair<ll, ll>
struct DSU{
vector<int> p;
int n, cnt;
DSU(int N){
n=N;
cnt=n;
p.resize(n, -1);
}
int get(int x){
return p[x]==-1?x:p[x]=get(p[x]);
}
bool unite(int a, int b){
a=get(a);
b=get(b);
if (a==b) return 0;
cnt--;
if (a<b) swap(a, b);
p[a]=b;
return 1;
}
};
int construct(std::vector<std::vector<int>> p) {
int n = (int)p.size();
DSU tr(n), tr2(n);
vector<vector<int>> A(n);
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
if (i!=j and p[i][j]){
tr.unite(i, j);
if (p[i][j]==1) tr2.unite(i, j);
}
}
}
map<int, vector<int>> ccs;
for (int i=0; i<n; i++){
// assert(tr.get(i)<tr.cnt);
ccs[tr.get(i)].push_back(i);
}
vector<vector<int>> ans(n, vector<int>(n));
vector<vector<int>> shadow(n, vector<int>(n));
for (auto &[_, arr]:ccs){
map<int, vector<int>> groups;
for (auto ch:arr){
groups[tr2.get(ch)].push_back(ch);
}
vector<int> circle;
for (auto &[icc,mem]:groups){
for (ll j=1; j<(int)mem.size(); j++){
ans[mem[j]][mem[j-1]]=ans[mem[j-1]][mem[j]]=1;
}
for (ll j=0; j<(int)mem.size(); j++){
for (ll k=j+1; k<(int)mem.size(); k++){
shadow[mem[j]][mem[k]]=shadow[mem[k]][mem[j]]=1;
}
}
circle.push_back(mem[0]);
}
if (circle.size()==1) continue;
for (ll j=0; j<(int)circle.size(); j++){
int nxt = (j+1)%(int)(circle.size());
ans[circle[j]][circle[nxt]]=ans[circle[nxt]][circle[j]]=1;
}
for (ll j=0; j<(int)(circle.size()); j++){
for (ll k=j+1; k<(int)(circle.size()); k++){
shadow[circle[j]][circle[k]]=shadow[circle[k]][circle[j]]=2;
}
}
}
for (ll i=0; i<n; i++){
for (ll j=0; j<n; j++){
if ((i!=j and p[i][j]!=shadow[i][j]) or p[i][j]==3){
return 0;
}
}
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
128 ms |
26108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
128 ms |
26108 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 |
344 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
117 ms |
26100 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
67 ms |
17964 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
29 ms |
7192 KB |
Output is correct |
21 |
Correct |
115 ms |
28248 KB |
Output is correct |
22 |
Correct |
159 ms |
28008 KB |
Output is correct |
23 |
Correct |
127 ms |
27884 KB |
Output is correct |
24 |
Correct |
117 ms |
28064 KB |
Output is correct |
25 |
Correct |
57 ms |
18004 KB |
Output is correct |
26 |
Correct |
54 ms |
18036 KB |
Output is correct |
27 |
Correct |
121 ms |
27988 KB |
Output is correct |
28 |
Correct |
112 ms |
27984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
28 ms |
6744 KB |
Output is correct |
5 |
Correct |
119 ms |
25940 KB |
Output is correct |
6 |
Correct |
116 ms |
26120 KB |
Output is correct |
7 |
Correct |
132 ms |
25956 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
32 ms |
6908 KB |
Output is correct |
10 |
Correct |
122 ms |
26124 KB |
Output is correct |
11 |
Correct |
117 ms |
26376 KB |
Output is correct |
12 |
Correct |
120 ms |
25936 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Incorrect |
0 ms |
344 KB |
Answer gives possible 0 while actual possible 1 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
128 ms |
26108 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 |
344 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
117 ms |
26100 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
67 ms |
17964 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
29 ms |
7192 KB |
Output is correct |
21 |
Correct |
115 ms |
28248 KB |
Output is correct |
22 |
Correct |
159 ms |
28008 KB |
Output is correct |
23 |
Correct |
127 ms |
27884 KB |
Output is correct |
24 |
Correct |
117 ms |
28064 KB |
Output is correct |
25 |
Correct |
57 ms |
18004 KB |
Output is correct |
26 |
Correct |
54 ms |
18036 KB |
Output is correct |
27 |
Correct |
121 ms |
27988 KB |
Output is correct |
28 |
Correct |
112 ms |
27984 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
0 ms |
344 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
128 ms |
26108 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 |
344 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
117 ms |
26100 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1116 KB |
Output is correct |
17 |
Correct |
67 ms |
17964 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
29 ms |
7192 KB |
Output is correct |
21 |
Correct |
115 ms |
28248 KB |
Output is correct |
22 |
Correct |
159 ms |
28008 KB |
Output is correct |
23 |
Correct |
127 ms |
27884 KB |
Output is correct |
24 |
Correct |
117 ms |
28064 KB |
Output is correct |
25 |
Correct |
57 ms |
18004 KB |
Output is correct |
26 |
Correct |
54 ms |
18036 KB |
Output is correct |
27 |
Correct |
121 ms |
27988 KB |
Output is correct |
28 |
Correct |
112 ms |
27984 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
0 ms |
344 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |