| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 711771 | Luicosas | Slagalica (COCI19_slagalica2) | C++17 | 47 ms | 8704 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define sz(x) (int)(x.size())
#define itr(x) x.begin(), x.end()
#define prv(x) for(auto& i : x) cout << i << " "; cout << "\n";
#ifdef LOCAL
#define debug(...) cerr << #__VA_ARGS__ << " : "; for(auto& i : {__VA_ARGS__}) cerr << i << " "; cerr << "\n";
#else 
#define debug(...)
#endif
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    array<int,2> st, en, o{0, 0};
    vector<vector<array<int,2>>> adj(2);
    for(int i = 0; i < n; i++) {
        int type, val;
        cin >> type >> val;
        if(type == 1) {
            adj[0].pb({val, 1});
            o[0] += 1;
            o[1] -= 1;
        } else if(type == 2) {
            adj[0].pb({val, 0});
        } else if(type == 3) {
            adj[1].pb({val, 1});
        } else if(type == 4) {
            adj[1].pb({val, 0});
            o[1] += 1;
            o[0] -= 1;
        } else if(type == 5) {
            st = {1, val};
        } else if(type == 6) {
            st = {0, val};
        } else if(type == 7) {
            en = {0, val};
        } else if(type == 8) {
            en = {1, val};
        } 
    }
    if(st[0] != en[0] && !(o[st[0]] == 1 && o[en[0]] == -1)) {
        cout << -1 << "\n";
        return 0;
    }
    if(st[0] == en[0] && !(o[0] == 0 && o[1] == 0)) {
        cout << -1 << "\n";
        return 0;
    }
    sort(itr(adj[0]));
    sort(itr(adj[1]));
    vector<int> ans, checked(2, 0);
    function<void(int)> dfs = [&](int idx) {
        if(checked[idx] == sz(adj[idx])) {
            return;
        } 
        while(checked[idx] < sz(adj[idx])) {
            auto& e = adj[idx][checked[idx]]; 
            checked[idx]++;
            dfs(e[1]);
            ans.pb(e[0]);
        }
    };
    dfs(st[0]);
    cout << st[1] << " ";
    for(int i = n - 3; i >= 0; i--) {
        cout << ans[i] << " ";
    }
    cout << en[1] << "\n";
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
