#include "supertrees.h"
#include <bits/stdc++.h>
#define sz(x) (int)(x.size())
using namespace std;
vector<int> a, b;
vector<vector<int>> answer;
vector<int> done;
// void build(vector<vector<int>> ans) {
// for (auto x : ans) {
// for (auto y : x) {
// cout << y << " ";
// }
// cout << "\n";
// }
// }
bool check1(int x, int n, vector<vector<int>> p) {
int c = 0;
for (int i = 0; i < n; ++i) {
if (p[x][i] == 1) {
if (done[i] != 1) return 0;
++c;
}
}
return (c == sz(a));
}
bool check2(int x, int n, vector<vector<int>> p) {
int c = 1;
for (int i = 0; i < n; ++i) {
if (i != x) {
if (p[x][i] == 2) {
// if (done[i] != 2) {
// cout << "here - " << x << " " << i << "\n";
// return 0;
// }
++c;
}
}
}
// cout << "c = " << c << "\n";
return (c == (sz(a) + sz(b)));
}
void place(int x, int n, vector<vector<int>> p) {
bool y = 0;
int z = 0;
done[x] = 3;
for (int i = 0; i < n; ++i) {
if (i != x && p[x][i]) {
if (p[x][i] == 1) {
// cout << x << " " << i << "\n";
y = 1;
}
if (done[i] == 0) place(i, n, p);
}
if (p[x][i] == 0) ++z;
}
if (z == n-1) return;
if (y) {
a.push_back(x);
done[x] = 1;
}
else {
b.push_back(x);
done[x] = 2;
}
}
int construct(vector<vector<int>> p) {
int n = p.size();
for (int i = 0; i < n; i++) {
done.push_back(0);
vector<int> row;
row.resize(n);
answer.push_back(row);
}
for (int i = 0; i < n; ++i) {
if (done[i] == 0) place(i, n, p);
else continue;
// if (done[i] == 1) cout << check1(i, n, p) << " - 1\n";
// else cout << check2(i, n, p) << " - 2\n";
if (done[i] == 3) continue;
if (sz(b) <= 2 && sz(a) == 0) {
// cout << 2 << "\n";
return 0;
}
for (int j = 1; j < sz(a); ++j) {
answer[0][j] = 1;
answer[j][0] = 1;
}
if (sz(a) && sz(b)) {
answer[a[0]][b[0]] = 1;
answer[b[0]][a[0]] = 1;
answer[a[0]][b[sz(b)-1]] = 1;
answer[b[sz(b)-1]][a[0]] = 1;
}
for (int j = 0; j < sz(b)-1; ++j) {
answer[b[j]][b[j+1]] = 1;
answer[b[j+1]][b[j]] = 1;
}
a.clear();
b.clear();
// for (auto x : done) cout << x << " ";
// for (auto x : a) cout << x << " ";
// cout << "\n";
// for (auto x : b) cout << x << " ";
// cout << "\n";
}
// for (int i = 1; i < n; ++i) {
// answer[0][i] = 1;
// answer[i][0] = 1;
// }
build(answer);
return 1;
}
// int main() {
// int n, a;
// cin >> n;
// vector<vector<int>> p;
// for (int i = 0; i < n; ++i) {
// p.push_back({});
// for (int j = 0; j < n; ++j) {
// cin >> a;
// p[i].push_back(a);
// }
// }
// construct(p);
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
22 ms |
33748 KB |
Output is correct |
7 |
Execution timed out |
1120 ms |
2053868 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
22 ms |
33748 KB |
Output is correct |
7 |
Execution timed out |
1120 ms |
2053868 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Too few ways to get from 0 to 1, should be 2 found 1 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
296 KB |
Too few ways to get from 0 to 1, should be 2 found 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
22 ms |
33748 KB |
Output is correct |
7 |
Execution timed out |
1120 ms |
2053868 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
22 ms |
33748 KB |
Output is correct |
7 |
Execution timed out |
1120 ms |
2053868 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |