// Author: Kajetan Ramsza
#include "bits/stdc++.h"
#include "supertrees.h"
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename F, typename S> ostream& operator<<(ostream& os, const pair<F, S> &p) { return os<<"("<<p.first<<", "<<p.second<<")"; }
template<typename T> ostream &operator<<(ostream & os, const vector<T> &v) { os << "{"; typename vector< T > :: const_iterator it;
for( it = v.begin(); it != v.end(); it++ ) { if( it != v.begin() ) os << ", "; os << *it; } return os << "}"; }
void dbg_out() { cerr<<'\n'; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr<<' '<<H; dbg_out(T...); }
#ifdef DEBUG
#define dbg(...) cerr<<"(" << #__VA_ARGS__ <<"):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
struct DSU {
vi dsu, siz;
DSU(int n) : dsu(n), siz(n, 1) {
iota(all(dsu), 0);
}
int find(int x) {
if(dsu[x] == x) return x;
return dsu[x] = find(dsu[x]);
}
void merge(int a, int b) {
a = find(a); b = find(b);
if(a == b) return;
if(siz[a] < siz[b]) swap(a, b);
else if(siz[a] == siz[b]) siz[a]++;
dsu[b] = a;
}
bool same(int a, int b) {
return find(a) == find(b);
}
};
int n;
vector<vi> answer;
pair<bool, vi> find_connected(vector<vi> &p) {
DSU dsu(n);
rep(i,0,n) rep(j,0,n)
if(p[i][j] > 0) dsu.merge(i, j);
rep(i,0,n) rep(j,0,n)
if(p[i][j] == 0 && dsu.same(i, j))
return {false, {}};
return {true, dsu.dsu};
}
int construct(vector<vi> p) {
n = p.size();
answer.assign(n, vi(n, 0));
auto [correct, connected_components] = find_connected(p);
dbg(connected_components);
if(!correct) return 0;
rep(i,0,n) {
if(connected_components[i] == i) continue;
answer[i][connected_components[i]] = 1;
answer[connected_components[i]][i] = 1;
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
428 KB |
Output is correct |
6 |
Correct |
5 ms |
1112 KB |
Output is correct |
7 |
Correct |
120 ms |
22100 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
428 KB |
Output is correct |
6 |
Correct |
5 ms |
1112 KB |
Output is correct |
7 |
Correct |
120 ms |
22100 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 |
5 ms |
1184 KB |
Output is correct |
13 |
Correct |
113 ms |
24044 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
936 KB |
Output is correct |
17 |
Correct |
62 ms |
14216 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
30 ms |
6348 KB |
Output is correct |
21 |
Correct |
117 ms |
23888 KB |
Output is correct |
22 |
Correct |
116 ms |
24104 KB |
Output is correct |
23 |
Correct |
119 ms |
23944 KB |
Output is correct |
24 |
Correct |
121 ms |
24064 KB |
Output is correct |
25 |
Correct |
51 ms |
14160 KB |
Output is correct |
26 |
Correct |
48 ms |
14208 KB |
Output is correct |
27 |
Correct |
120 ms |
23924 KB |
Output is correct |
28 |
Correct |
114 ms |
23888 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Too few ways to get from 0 to 1, should be 2 found 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
428 KB |
Output is correct |
6 |
Correct |
5 ms |
1112 KB |
Output is correct |
7 |
Correct |
120 ms |
22100 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 |
5 ms |
1184 KB |
Output is correct |
13 |
Correct |
113 ms |
24044 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
936 KB |
Output is correct |
17 |
Correct |
62 ms |
14216 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
30 ms |
6348 KB |
Output is correct |
21 |
Correct |
117 ms |
23888 KB |
Output is correct |
22 |
Correct |
116 ms |
24104 KB |
Output is correct |
23 |
Correct |
119 ms |
23944 KB |
Output is correct |
24 |
Correct |
121 ms |
24064 KB |
Output is correct |
25 |
Correct |
51 ms |
14160 KB |
Output is correct |
26 |
Correct |
48 ms |
14208 KB |
Output is correct |
27 |
Correct |
120 ms |
23924 KB |
Output is correct |
28 |
Correct |
114 ms |
23888 KB |
Output is correct |
29 |
Correct |
0 ms |
348 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 |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
428 KB |
Output is correct |
6 |
Correct |
5 ms |
1112 KB |
Output is correct |
7 |
Correct |
120 ms |
22100 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 |
5 ms |
1184 KB |
Output is correct |
13 |
Correct |
113 ms |
24044 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
936 KB |
Output is correct |
17 |
Correct |
62 ms |
14216 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
30 ms |
6348 KB |
Output is correct |
21 |
Correct |
117 ms |
23888 KB |
Output is correct |
22 |
Correct |
116 ms |
24104 KB |
Output is correct |
23 |
Correct |
119 ms |
23944 KB |
Output is correct |
24 |
Correct |
121 ms |
24064 KB |
Output is correct |
25 |
Correct |
51 ms |
14160 KB |
Output is correct |
26 |
Correct |
48 ms |
14208 KB |
Output is correct |
27 |
Correct |
120 ms |
23924 KB |
Output is correct |
28 |
Correct |
114 ms |
23888 KB |
Output is correct |
29 |
Correct |
0 ms |
348 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 |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |