#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define N 100005
#define wr cout << "Continue debugging\n";
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
int find(int i, vector<vector<int>> p, int n){
set<int> s;
for (int j = 0; j < n; j++){
if (p[i][j] and i != j) s.insert(p[i][j]);
}
if (s.size() > 1) return -1;
if (!s.size()) return -2;
return *s.begin();
}
int construct(vector<vector<int>> p){
int n = p.size();
vector<vector<int>> b(n, vector<int>(n, 0));
vector<int> vis(n+1, 0);
for (int i = 0; i < n; i++){
if (vis[i]) continue;
int x = find(i, p, n);
if (x == -1) return 0;
if (x == -2) continue;
vector<int> vec;
for (int j = 0; j < n; j++){
if (p[i][j] and i != j) b[i][j] = b[j][i] = vis[j] = 1;
else if (!p[i][j]) vec.pb(j);
}
for (int j = 0; j < n; j++){
if (!p[i][j] or i == j) continue;
for (auto k : vec) if (p[j][k]) return 0;
}
if (x == 2){
int a1 = -1, b1 = -1;
for (int j = 0; j < n; j++){
if (p[i][j] and i != j){
if (a1 == -1) a1 = j;
else b1 = j;
}
}
if (b1 == -1) return 0;
b[a1][b1] = b[b1][a1] = 1;
}
}
// for (int i = 0; i < n; i++){
// for (int j = 0; j < n; j++) cout << b[i][j] << ' ';
// cout << '\n';
// }
build(b);
return 1;
}
// int main ()
// {
// int n;
// cin >> n;
// vector<vector<int>> p(n, vector<int>(n));
// for (int i = 0; i < n; i++){
// for (int j = 0; j < n; j++) cin >> p[i][j];
// }
// int x = construct(p);
// }
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
6 ms |
1152 KB |
Output is correct |
7 |
Correct |
147 ms |
23960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
6 ms |
1152 KB |
Output is correct |
7 |
Correct |
147 ms |
23960 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
300 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
10 ms |
1188 KB |
Output is correct |
13 |
Execution timed out |
1038 ms |
23932 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
296 KB |
Output is correct |
6 |
Correct |
0 ms |
224 KB |
Output is correct |
7 |
Correct |
0 ms |
300 KB |
Output is correct |
8 |
Correct |
12 ms |
1240 KB |
Output is correct |
9 |
Execution timed out |
1080 ms |
24028 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
54 ms |
6176 KB |
Output is correct |
5 |
Correct |
164 ms |
23972 KB |
Output is correct |
6 |
Correct |
566 ms |
23964 KB |
Output is correct |
7 |
Correct |
152 ms |
23980 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
Too few ways to get from 0 to 2, should be 2 found 1 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
6 ms |
1152 KB |
Output is correct |
7 |
Correct |
147 ms |
23960 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
300 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
10 ms |
1188 KB |
Output is correct |
13 |
Execution timed out |
1038 ms |
23932 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
6 ms |
1152 KB |
Output is correct |
7 |
Correct |
147 ms |
23960 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
300 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
10 ms |
1188 KB |
Output is correct |
13 |
Execution timed out |
1038 ms |
23932 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |