// Source:https://ioinformatics.org/files/ioi2020problem2.pdf
//
#include "supertrees.h"
#include "bits/stdc++.h"
using namespace std;
#define s second
#define f first
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<int> vi;
#define FOR(i, a, b) for (int i = (a); i<b; i++)
bool ckmin(int& a, int b){ return b < a ? a = b, true : false; }
bool ckmax(int& a, int b){ return b > a ? a = b, true : false; }
vector<vi> pth;
vector<vi> sol;
int n;
vector<bool> vis;
bool works=true;
vector<vi> p;
void solve(vi here) {
// cout << 'd' << endl;
vi cyc;
vi ncyc;
for (auto i: here) {
bool fail=true;
for (auto j: here) {
if (i != j && p[i][j] != 2) {
fail=false;
}
}
if (!fail) ncyc.pb(i);
else cyc.pb(i);
}
for (auto i: ncyc) {
for (auto j: ncyc) {
if (p[i][j] != 1) works=false;
// cout << i << j << p[i][j] << endl;
}
}
int chosen;
if (ncyc.size()) {
chosen = ncyc.back();
ncyc.pop_back();
}
// cout << cyc.size() << endl;
FOR(i, 0, ((int) cyc.size()) - 1) {
// cout << cyc[i] << endl;
sol[cyc[i]][cyc[i + 1]] = 1;
sol[cyc[i + 1]][cyc[i]] = 1;
}
// cout << 'd' << endl;
if (cyc.size() && ncyc.size()) {
sol[chosen][cyc[0]]=1;
sol[cyc[0]][chosen]=1;
sol[chosen][cyc[cyc.size() - 1]]=1;
sol[cyc[cyc.size() - 1]][chosen]=1;
}
if (ncyc.size()) {
sol[ncyc[0]][chosen] = 1;
sol[chosen][ncyc[0]] = 1;
FOR(i, 0, ncyc.size() - 1) {
sol[ncyc[i]][ncyc[i + 1]] = 1;
sol[ncyc[i + 1]][ncyc[i]] = 1;
}
}
}
// void build(vector<vi> t) {
// for (auto val: t) {
// for (auto j: val) {
// cout << j << ' ';
// }
// cout << endl;
// }
// }
int construct(vector<vi> P) {
n = P.size();
p = P;
sol = vector<vi>(n, vi(n, 0));
vis.resize(n);
FOR(i, 0, n) {
if (!vis[i]) {
vi here;
FOR(j, 0, n) {
if (p[i][j]) {
vis[j]=true;
here.pb(j);
}
}
// cout << i << endl;
solve(here);
}
}
if (!works) return 0;
build(sol);
return 1;
}
// int main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// // cout << construct({{1, 1, 2, 2}, {1, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}}) << endl;
// cout << construct({{1, 1}, {1, 1}}) << endl;
// }
Compilation message
supertrees.cpp: In function 'void solve(vi)':
supertrees.cpp:19:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | #define FOR(i, a, b) for (int i = (a); i<b; i++)
......
81 | FOR(i, 0, ncyc.size() - 1) {
| ~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:81:3: note: in expansion of macro 'FOR'
81 | FOR(i, 0, ncyc.size() - 1) {
| ^~~
supertrees.cpp:71:13: warning: 'chosen' may be used uninitialized in this function [-Wmaybe-uninitialized]
71 | sol[chosen][cyc[0]]=1;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1368 KB |
Output is correct |
7 |
Correct |
150 ms |
27948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1368 KB |
Output is correct |
7 |
Correct |
150 ms |
27948 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1468 KB |
Output is correct |
13 |
Correct |
175 ms |
27896 KB |
Output is correct |
14 |
Incorrect |
0 ms |
428 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
496 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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1368 KB |
Output is correct |
7 |
Correct |
150 ms |
27948 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1468 KB |
Output is correct |
13 |
Correct |
175 ms |
27896 KB |
Output is correct |
14 |
Incorrect |
0 ms |
428 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1368 KB |
Output is correct |
7 |
Correct |
150 ms |
27948 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1468 KB |
Output is correct |
13 |
Correct |
175 ms |
27896 KB |
Output is correct |
14 |
Incorrect |
0 ms |
428 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |