#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define inf 1000000000
#define sz(x) (ll)x.size()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair< int , pii> piii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
typedef pair<ld , ld> pdd;
typedef vector<ld> vd;
typedef vector<vector<pib>> vvib;
typedef vector<piii> viii;
typedef vector<viii> vviii;
typedef vector<bool> vb;
typedef pair<pii , bool> piib;
typedef vector<pair<pii , bool>> viib;
const int MOD = 1e9 + 7; //998244353;
const int MAXN = 100005;
int n;
struct UnionFind{
public:
vi par;
UnionFind(){
for(int i = 0;i<n;i++)par[i] = i;
}
void init(){
par.resize(n);
for(int i = 0;i<n;i++)par[i] = i;
}
int findset(int x){
if(par[x] == x)return x;
return par[x] = findset(par[x]);
}
void Union(int x , int y){
x = findset(x);
y = findset(y);
if(x != y){
par[x] = y;
}
}
};
UnionFind components;
UnionFind branches;
vvi ans;
bool v[1005];
bool v0[1005];
int construct(vvi p){
n = p.size();
ans.assign(n ,vi(n ,0));
components.init();
branches.init();
memset(v , 0 , 1005);
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
if(p[i][j] == 3)return 0;
if(p[i][j] >= 1)components.Union(i, j);
if(p[i][j] == 1)branches.Union(i,j);
}
}
for(int i = 0;i<n;i++){
int c = 0;
for(int j = 0;j<n;j++){
if(p[i][j] == 0){
if(components.findset(i) == components.findset(j))return 0;
}
if(p[i][j] == 2 && branches.findset(i) == branches.findset(j))return 0;
if(p[i][j] == 2){
int y = branches.findset(j);
if(v[y])continue;
v[y] = 1;
c++;
}
}
if(c == 1)return 0;
memset(v , 0 , sizeof v);
}
memset(v0 , 0 , 1005);
for(int i = 0;i<n;i++){
int x = branches.findset(i);
if(v[x])continue;
vi res;
for(int j = 0;j<n;j++){
if(branches.findset(j) == x)res.pb(j);
}
v[x] = 1;
if(res.size() <= 1)continue;
for(int j = 0;j<res.size()-1;j++){
ans[res[j]][res[j+1]] = 1;
ans[res[j+1]][res[j]] = 1;
}
}
memset(v , 0 , 1005);
for(int i = 0;i<n;i++){
int x = components.findset(i);
if(v0[x])continue;
vi res;
v0[x] = 1;
for(int j = 0;j<n;j++){
int y = branches.findset(j);
if(v[y])continue;
v[y] = 1;
if(components.findset(y) == x)res.pb(y);
}
if(res.size() <= 1)continue;
for(int j = 0;j<res.size()-1;j++){
ans[res[j]][res[j+1]] = 1;
ans[res[j+1]][res[j]] = 1;
}
ans[res.front()][res.back()] = 1;
ans[res.back()][res.front()] = 1;
}
build(ans);
return 1;
}
//NEVER GIVE UP
//LONG LONG
Compilation message
supertrees.cpp: In function 'int construct(vvi)':
supertrees.cpp:112:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for(int j = 0;j<res.size()-1;j++){
| ~^~~~~~~~~~~~~
supertrees.cpp:130:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
130 | for(int j = 0;j<res.size()-1;j++){
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
1152 KB |
Output is correct |
7 |
Correct |
240 ms |
22108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
1152 KB |
Output is correct |
7 |
Correct |
240 ms |
22108 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1228 KB |
Output is correct |
13 |
Correct |
240 ms |
22064 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
112 ms |
12152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
61 ms |
5752 KB |
Output is correct |
21 |
Correct |
249 ms |
22052 KB |
Output is correct |
22 |
Correct |
245 ms |
22128 KB |
Output is correct |
23 |
Correct |
260 ms |
22136 KB |
Output is correct |
24 |
Correct |
247 ms |
22068 KB |
Output is correct |
25 |
Correct |
108 ms |
12152 KB |
Output is correct |
26 |
Correct |
102 ms |
12120 KB |
Output is correct |
27 |
Correct |
258 ms |
22108 KB |
Output is correct |
28 |
Correct |
250 ms |
22156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
10 ms |
1152 KB |
Output is correct |
9 |
Correct |
259 ms |
22104 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1152 KB |
Output is correct |
13 |
Correct |
250 ms |
22104 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
110 ms |
12152 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
0 ms |
256 KB |
Output is correct |
21 |
Incorrect |
60 ms |
5752 KB |
Too few ways to get from 1 to 17, should be 2 found 0 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
62 ms |
5752 KB |
Output is correct |
5 |
Correct |
242 ms |
22136 KB |
Output is correct |
6 |
Correct |
241 ms |
22136 KB |
Output is correct |
7 |
Correct |
253 ms |
22136 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Incorrect |
59 ms |
5752 KB |
Too few ways to get from 1 to 17, should be 2 found 0 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
1152 KB |
Output is correct |
7 |
Correct |
240 ms |
22108 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1228 KB |
Output is correct |
13 |
Correct |
240 ms |
22064 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
112 ms |
12152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
61 ms |
5752 KB |
Output is correct |
21 |
Correct |
249 ms |
22052 KB |
Output is correct |
22 |
Correct |
245 ms |
22128 KB |
Output is correct |
23 |
Correct |
260 ms |
22136 KB |
Output is correct |
24 |
Correct |
247 ms |
22068 KB |
Output is correct |
25 |
Correct |
108 ms |
12152 KB |
Output is correct |
26 |
Correct |
102 ms |
12120 KB |
Output is correct |
27 |
Correct |
258 ms |
22108 KB |
Output is correct |
28 |
Correct |
250 ms |
22156 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
1 ms |
256 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
1 ms |
256 KB |
Output is correct |
35 |
Correct |
1 ms |
256 KB |
Output is correct |
36 |
Correct |
10 ms |
1152 KB |
Output is correct |
37 |
Correct |
259 ms |
22104 KB |
Output is correct |
38 |
Correct |
1 ms |
256 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
11 ms |
1152 KB |
Output is correct |
41 |
Correct |
250 ms |
22104 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
256 KB |
Output is correct |
44 |
Correct |
5 ms |
768 KB |
Output is correct |
45 |
Correct |
110 ms |
12152 KB |
Output is correct |
46 |
Correct |
0 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
256 KB |
Output is correct |
48 |
Correct |
0 ms |
256 KB |
Output is correct |
49 |
Incorrect |
60 ms |
5752 KB |
Too few ways to get from 1 to 17, should be 2 found 0 |
50 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
1152 KB |
Output is correct |
7 |
Correct |
240 ms |
22108 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1228 KB |
Output is correct |
13 |
Correct |
240 ms |
22064 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
112 ms |
12152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
61 ms |
5752 KB |
Output is correct |
21 |
Correct |
249 ms |
22052 KB |
Output is correct |
22 |
Correct |
245 ms |
22128 KB |
Output is correct |
23 |
Correct |
260 ms |
22136 KB |
Output is correct |
24 |
Correct |
247 ms |
22068 KB |
Output is correct |
25 |
Correct |
108 ms |
12152 KB |
Output is correct |
26 |
Correct |
102 ms |
12120 KB |
Output is correct |
27 |
Correct |
258 ms |
22108 KB |
Output is correct |
28 |
Correct |
250 ms |
22156 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
1 ms |
256 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
1 ms |
256 KB |
Output is correct |
35 |
Correct |
1 ms |
256 KB |
Output is correct |
36 |
Correct |
10 ms |
1152 KB |
Output is correct |
37 |
Correct |
259 ms |
22104 KB |
Output is correct |
38 |
Correct |
1 ms |
256 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
11 ms |
1152 KB |
Output is correct |
41 |
Correct |
250 ms |
22104 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
256 KB |
Output is correct |
44 |
Correct |
5 ms |
768 KB |
Output is correct |
45 |
Correct |
110 ms |
12152 KB |
Output is correct |
46 |
Correct |
0 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
256 KB |
Output is correct |
48 |
Correct |
0 ms |
256 KB |
Output is correct |
49 |
Incorrect |
60 ms |
5752 KB |
Too few ways to get from 1 to 17, should be 2 found 0 |
50 |
Halted |
0 ms |
0 KB |
- |