55512023-07-24 18:22:47Valaki2Széfnyitáscpp17Accepted 100/1004ms4824 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
 
int n;
 
struct subset {
    vector<bool> inout;
    subset() {
        inout.assign(1 + n, false);
    }
    bool operator < (const subset & other) const {
        return inout < other.inout;
    }
};
 
subset DEF;
 
struct ansrow {
    int b;
    int t[2];
};
 
int k;
vector<int> a;
vector<vector<int> > s;
map<subset, int> sbs; // subsets
vector<ansrow> ans;
 
subset step(subset nodes, bool bit) {
    subset res = DEF;
    for(int i = 1; i <= n; i++) {
        if(nodes.inout[i]) {
            res.inout[s[i][bit]] = true;
        }
    }
    return res;
}
 
pair<bool, int> create_for(subset nodes) {
    int partialresult = sbs[nodes];
    /*cout << "???: ";
    for(int i = 1; i <= n; i++) {
        cout << nodes.inout[i];
    }
    cout << "\n";*/
    if(partialresult) {
        return mp(false, partialresult);
    }
    int idx = ans.size();
    sbs[nodes] = idx;
    ans.pb(ansrow());
    return mp(true, idx);
}
 
void solve_for(subset nodes, int idx) {
    vector<bool> has(2, false);
    for(int i = 1; i <= n; i++) {
        if(nodes.inout[i]) {
            has[a[i]] = true;
        }
    }
    if(!has[0] && !has[1]) {
        exit(1);
    }
    if(has[0] && has[1]) {
        bool which = false;
        subset with_0 = DEF;
        subset with_1 = DEF;
        for(int i = 1; i <= n; i++) {
            if(nodes.inout[i]) {
                if(a[i] == 0) {
                    with_0.inout[i] = true;
                } else if(a[i] == 1) {
                    with_1.inout[i] = true;
                }
            }
        }
        //cout << idx << " " << with_0.inout[1] << with_0.inout[2] << with_1.inout[1] << with_1.inout[2] << "!!!\n";
        ans[idx].b = which;
        subset nw0 = step(with_0, which);
        pair<bool, int> res0 = create_for(nw0);
        //cout << "res: " << res0.fi << " " << res0.se << "\n";
        ans[idx].t[false] = res0.se;
        if(res0.fi) {
            solve_for(nw0, res0.se);
        }
        subset nw1 = step(with_1, which);
        pair<bool, int> res1 = create_for(nw1);
        ans[idx].t[true] = res1.se;
        if(res1.fi) {
            solve_for(nw1, res1.se);
        }
    } else {
        bool which = has[1];
        subset nw = step(nodes, which);
        pair<bool, int> res = create_for(nw);
        ans[idx] = {which, res.se, res.se};
        if(res.fi) {
            solve_for(nw, res.se);
        }
    }
}
 
void solve() {
    cin >> n;
    DEF.inout.assign(1 + n, false);
    a.assign(1 + n, 0);
    s.assign(1 + n, vector<int> (2, 0));
    for(int i = 1; i <= n; i++) {
        cin >> a[i] >> s[i][0] >> s[i][1];
    }
    cin >> k;
    subset all = DEF;
    for(int i = 1; i <= n; i++) {
        all.inout[i] = true;
    }
    //cout << all.inout.size() << "\n";
    ans.resize(1);
    create_for(all);
    solve_for(all, 1);
    cout << (ans.size() - 1) << " " << 1 << "\n";
    for(int i = 1; i < ans.size(); i++) {
        cout << ans[i].b << " " << ans[i].t[0] << " " << ans[i].t[1] << "\n";
    }
}
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
 
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1888 KiB
2Accepted3ms1952 KiB
subtask216/16
3Accepted3ms2168 KiB
4Accepted3ms2388 KiB
5Accepted3ms2604 KiB
6Accepted3ms3088 KiB
7Accepted3ms3032 KiB
8Accepted3ms3240 KiB
9Accepted3ms3328 KiB
10Accepted2ms3368 KiB
11Accepted3ms3472 KiB
12Accepted3ms3704 KiB
13Accepted3ms3736 KiB
subtask324/24
14Accepted3ms3812 KiB
15Accepted3ms3828 KiB
16Accepted2ms3840 KiB
17Accepted2ms3836 KiB
18Accepted3ms3976 KiB
19Accepted3ms4064 KiB
20Accepted3ms4220 KiB
21Accepted3ms4180 KiB
subtask423/23
22Accepted3ms4304 KiB
23Accepted2ms4396 KiB
24Accepted3ms4404 KiB
25Accepted3ms4492 KiB
26Accepted3ms4508 KiB
27Accepted3ms4780 KiB
28Accepted3ms4324 KiB
29Accepted3ms4420 KiB
subtask537/37
30Accepted3ms2168 KiB
31Accepted3ms2388 KiB
32Accepted3ms2604 KiB
33Accepted3ms3088 KiB
34Accepted3ms3032 KiB
35Accepted3ms3240 KiB
36Accepted3ms3328 KiB
37Accepted2ms3368 KiB
38Accepted3ms3472 KiB
39Accepted3ms3704 KiB
40Accepted3ms3736 KiB
41Accepted3ms3812 KiB
42Accepted3ms3828 KiB
43Accepted2ms3840 KiB
44Accepted2ms3836 KiB
45Accepted3ms3976 KiB
46Accepted3ms4064 KiB
47Accepted3ms4220 KiB
48Accepted3ms4180 KiB
49Accepted3ms4304 KiB
50Accepted2ms4396 KiB
51Accepted3ms4404 KiB
52Accepted3ms4492 KiB
53Accepted3ms4508 KiB
54Accepted3ms4780 KiB
55Accepted3ms4324 KiB
56Accepted3ms4420 KiB
57Accepted3ms4460 KiB
58Accepted3ms4540 KiB
59Accepted3ms4632 KiB
60Accepted3ms4708 KiB
61Accepted4ms4736 KiB
62Accepted4ms4716 KiB
63Accepted4ms4668 KiB
64Accepted4ms4792 KiB
65Accepted4ms4812 KiB
66Accepted4ms4812 KiB
67Accepted4ms4820 KiB
68Accepted4ms4824 KiB