#include "supertrees.h"
#include<bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix= vector<vector<T>>;
struct UnionFind{
vector<int> pai;
matrix<int> group;
int n;
UnionFind(int sz = 0){
n = sz;
pai = vector<int>(n);
iota(all(pai),0);
group = matrix<int>(n);
for(int i = 0; i < n; i++)
group[i].push_back(i);
}
int find(int id){
if(pai[id] == id)
return id;
return pai[id] = find(pai[id]);
}
void onion(int a, int b){
a = find(a);
b = find(b);
if(a == b)
return;
if(group[a].size() > group[b].size())
swap(a,b);
for(int i : group[a])
group[b].push_back(i);
group[a].clear();
pai[a] = b;
}
};
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
matrix<int> resp(n,vector<int>(n));
UnionFind connected(n);
for (int i = 0; i < n; i++) {
for(int j = 0; j < n; j++){
if(p[i][j])
connected.onion(i,j);
}
}
auto solveforgroup =[&](vector<int>& g){
vector<int> incall(n);
for(int i : g)
incall[i] = 1;
int line = 1;
for(int i : g){
for(int j : g){
if(!p[i][j])
return 0;
line&=p[i][j];
}
}
if(line){
for(int i = 1; i < g.size(); i++){
resp[g[i-1]][g[i]] = 1;
resp[g[i]][g[i-1]] = 1;
}
return 1;
}
vector<int> count1(n);
for(int i : g){
for(int j : g){
count1[i]+=p[i][j] == 1;
}
}
vector<int> cycle, incycle(n);
for(int i : g){
if(count1[i] == 0)
cycle.push_back(i), incycle[i] = 0;
for(int j : g){
if(p[i][j] == 1 && count1[i] > count1[j]){
cycle.push_back(i);
incycle[i] = 1;
break;
}
}
}
UnionFind lines(n);
for(int i : g){
if(incycle[i])
continue;
for(int j : g){
if(p[i][j] == 1 && !incycle[j]){
}
}
}
return 1;
};
bool ok = 1;
for(vector<int>& i : connected.group){
if(i.size())
ok&=solveforgroup(i);
}
if(!ok)
return 0;
build(resp);
return 1;
}
Compilation message
supertrees.cpp: In lambda function:
supertrees.cpp:71:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i = 1; i < g.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
191 ms |
22016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
191 ms |
22016 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1176 KB |
Output is correct |
13 |
Correct |
169 ms |
22068 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
92 ms |
12168 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
44 ms |
5796 KB |
Output is correct |
21 |
Correct |
173 ms |
22092 KB |
Output is correct |
22 |
Correct |
175 ms |
22032 KB |
Output is correct |
23 |
Correct |
202 ms |
22016 KB |
Output is correct |
24 |
Correct |
174 ms |
22092 KB |
Output is correct |
25 |
Correct |
73 ms |
12196 KB |
Output is correct |
26 |
Correct |
86 ms |
12176 KB |
Output is correct |
27 |
Correct |
210 ms |
22116 KB |
Output is correct |
28 |
Correct |
168 ms |
22016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 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 |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Too few ways to get from 0 to 1, should be 2 found 0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
191 ms |
22016 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1176 KB |
Output is correct |
13 |
Correct |
169 ms |
22068 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
92 ms |
12168 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
44 ms |
5796 KB |
Output is correct |
21 |
Correct |
173 ms |
22092 KB |
Output is correct |
22 |
Correct |
175 ms |
22032 KB |
Output is correct |
23 |
Correct |
202 ms |
22016 KB |
Output is correct |
24 |
Correct |
174 ms |
22092 KB |
Output is correct |
25 |
Correct |
73 ms |
12196 KB |
Output is correct |
26 |
Correct |
86 ms |
12176 KB |
Output is correct |
27 |
Correct |
210 ms |
22116 KB |
Output is correct |
28 |
Correct |
168 ms |
22016 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Incorrect |
0 ms |
212 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 |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
7 |
Correct |
191 ms |
22016 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1176 KB |
Output is correct |
13 |
Correct |
169 ms |
22068 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
92 ms |
12168 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
44 ms |
5796 KB |
Output is correct |
21 |
Correct |
173 ms |
22092 KB |
Output is correct |
22 |
Correct |
175 ms |
22032 KB |
Output is correct |
23 |
Correct |
202 ms |
22016 KB |
Output is correct |
24 |
Correct |
174 ms |
22092 KB |
Output is correct |
25 |
Correct |
73 ms |
12196 KB |
Output is correct |
26 |
Correct |
86 ms |
12176 KB |
Output is correct |
27 |
Correct |
210 ms |
22116 KB |
Output is correct |
28 |
Correct |
168 ms |
22016 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |