#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)
#include "supertrees.h"
using namespace std;
template<class T1, class T2>
bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2>
bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2>
void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}
template<class T1, class T2>
void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}
template<class T>
void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int MAX = 1003;
int construct(vector<vector<int>> p){
int N = sz(p);
auto subtask1_check = [&]() -> bool{
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
if(p[i][j] != 1){
return false;
}
}
}
return true;
};
if(subtask1_check()){
vector<vector<int>> ans(N, vector<int>(N, 0));
for(int i = 1; i < N; i++){
ans[i - 1][i] = ans[i][i - 1] = 1;
}
build(ans);
return 1;
}
auto subtask2_check = [&]() -> bool{
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
if(p[i][j] != 0 && p[i][j] != 1){
return false;
}
}
}
return true;
};
if(subtask2_check()){
vector<vector<int>> ans(N, vector<int>(N, 0));
vector<int> visited(N, false), save;
auto dfs = [&](auto self, int u) -> void {
if(visited[u]) return;
visited[u] = true;
save.push_back(u);
for(int v = 0; v < N; v++) if(p[u][v]){
self(self, v);
}
};
for(int i = 0; i < N; i++) if(!visited[i]){
save.clear();
dfs(dfs, i);
for(int j = 0; j < sz(save); j++){
for(int k = j + 1; k < sz(save); k++){
if(p[save[j]][save[k]] == 0){
return 0;
}
}
}
for(int j = 1; j < sz(save); j++){
ans[save[j]][save[j - 1]] = ans[save[j - 1]][save[j]] = 1;
}
}
build(ans);
return 1;
}
auto subtask3_check = [&]() -> bool{
for(int i = 0; i < N; i++){
for(int j = i + 1; j < N; j++){
if(p[i][j] != 0 && p[i][j] != 2){
return false;
}
}
}
return true;
};
if(subtask3_check()){
vector<vector<int>> ans(N, vector<int>(N, 0));
vector<int> visited(N, false), save;
auto dfs = [&](auto self, int u) -> void {
if(visited[u]) return;
visited[u] = true;
save.push_back(u);
for(int v = 0; v < N; v++) if(p[u][v]){
self(self, v);
}
};
for(int i = 0; i < N; i++) if(!visited[i]){
save.clear();
dfs(dfs, i);
if(sz(save) == 1) continue;
for(int j = 0; j < sz(save); j++){
for(int k = j + 1; k < sz(save); k++){
if(p[save[j]][save[k]] == 0){
return 0;
}
}
}
for(int j = 1; j < sz(save); j++){
ans[save[j]][save[j - 1]] = ans[save[j - 1]][save[j]] = 1;
}
ans[save[0]][save.back()] = ans[save.back()][save[0]] = 1;
}
build(ans);
return 1;
}
return 0;
}
//int main(){
// ios_base::sync_with_stdio(0); cin.tie(0);
// // freopen("ADVERT.inp","r",stdin);
// // freopen("ADVERT.out","w",stdout);
//
// // cout << delivery(3, 2, 8, {1, 2, 5});
//
// return 0;
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
1104 KB |
Output is correct |
7 |
Correct |
125 ms |
22088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
1104 KB |
Output is correct |
7 |
Correct |
125 ms |
22088 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
6 ms |
1104 KB |
Output is correct |
13 |
Correct |
125 ms |
22040 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
4 ms |
848 KB |
Output is correct |
17 |
Correct |
68 ms |
12288 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
33 ms |
5712 KB |
Output is correct |
21 |
Correct |
133 ms |
22100 KB |
Output is correct |
22 |
Correct |
135 ms |
22088 KB |
Output is correct |
23 |
Correct |
133 ms |
22088 KB |
Output is correct |
24 |
Correct |
130 ms |
22088 KB |
Output is correct |
25 |
Correct |
59 ms |
12116 KB |
Output is correct |
26 |
Correct |
58 ms |
12060 KB |
Output is correct |
27 |
Correct |
138 ms |
22088 KB |
Output is correct |
28 |
Correct |
118 ms |
22044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1 ms |
336 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
38 ms |
6332 KB |
Output is correct |
5 |
Correct |
131 ms |
24136 KB |
Output is correct |
6 |
Correct |
133 ms |
24392 KB |
Output is correct |
7 |
Correct |
129 ms |
23940 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
33 ms |
6396 KB |
Output is correct |
10 |
Correct |
140 ms |
24136 KB |
Output is correct |
11 |
Correct |
130 ms |
24068 KB |
Output is correct |
12 |
Correct |
138 ms |
24080 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Incorrect |
1 ms |
336 KB |
Answer gives possible 0 while actual possible 1 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
1104 KB |
Output is correct |
7 |
Correct |
125 ms |
22088 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
6 ms |
1104 KB |
Output is correct |
13 |
Correct |
125 ms |
22040 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
4 ms |
848 KB |
Output is correct |
17 |
Correct |
68 ms |
12288 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
33 ms |
5712 KB |
Output is correct |
21 |
Correct |
133 ms |
22100 KB |
Output is correct |
22 |
Correct |
135 ms |
22088 KB |
Output is correct |
23 |
Correct |
133 ms |
22088 KB |
Output is correct |
24 |
Correct |
130 ms |
22088 KB |
Output is correct |
25 |
Correct |
59 ms |
12116 KB |
Output is correct |
26 |
Correct |
58 ms |
12060 KB |
Output is correct |
27 |
Correct |
138 ms |
22088 KB |
Output is correct |
28 |
Correct |
118 ms |
22044 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Incorrect |
1 ms |
336 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
1104 KB |
Output is correct |
7 |
Correct |
125 ms |
22088 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
6 ms |
1104 KB |
Output is correct |
13 |
Correct |
125 ms |
22040 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
4 ms |
848 KB |
Output is correct |
17 |
Correct |
68 ms |
12288 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
33 ms |
5712 KB |
Output is correct |
21 |
Correct |
133 ms |
22100 KB |
Output is correct |
22 |
Correct |
135 ms |
22088 KB |
Output is correct |
23 |
Correct |
133 ms |
22088 KB |
Output is correct |
24 |
Correct |
130 ms |
22088 KB |
Output is correct |
25 |
Correct |
59 ms |
12116 KB |
Output is correct |
26 |
Correct |
58 ms |
12060 KB |
Output is correct |
27 |
Correct |
138 ms |
22088 KB |
Output is correct |
28 |
Correct |
118 ms |
22044 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Incorrect |
1 ms |
336 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |