Submission #1004747

# Submission time Handle Problem Language Result Execution time Memory
1004747 2024-06-21T13:35:48 Z atom Logičari (COCI21_logicari) C++17
20 / 110
138 ms 7092 KB
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
 
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
 
const int N = 1e5 + 5;
// 1: last position of x, -1: second-last position of x -> sum(l, r) = 0-> non-unique subarray, > 0: unique

vector <int> adj[N];
int n;

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int x, y; cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    bool sub1 = true;
    for (int i = 1; i <= n; ++i) {
        if ((int) adj[i].size() != 2) sub1 = false;
    }

    if (sub1) {
        cout << (n % 4 == 0? (n / 2) : -1) << "\n";
        return 0;
    }

    bool sub2 = (n <= 20);
    if (sub2) {
        int res = 1e9;
        for (int msk = 0; msk < (1 << n); ++msk) {
            vector <bool> b(n + 1, 0);
            int cur = 0;
            for (int i = 1; i <= n; ++i) { 
                if (msk & (1 << (i - 1))) {
                    b[i] = 1;
                    ++cur;
                }
            }

            bool ans = true;    
            for (int i = 1; i <= n; ++i) {
                int cnt = 0;
                for (int j : adj[i])
                    if (b[j])
                        ++cnt;
                if (cnt != 1) ans = false;
            }

            if (ans) {
                res = min(res, cur);
            }
        }
        cout << (res != 1e9? res : -1) << "\n";
        return 0;
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2688 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 20 ms 7004 KB Output is correct
6 Correct 21 ms 7004 KB Output is correct
7 Correct 18 ms 7092 KB Output is correct
8 Correct 19 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 2652 KB Output is correct
2 Correct 132 ms 2652 KB Output is correct
3 Correct 130 ms 2652 KB Output is correct
4 Correct 133 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 65 ms 2776 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 32 ms 2652 KB Output is correct
9 Correct 130 ms 2652 KB Output is correct
10 Correct 138 ms 2648 KB Output is correct
11 Correct 16 ms 2652 KB Output is correct
12 Correct 133 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 2652 KB Output is correct
2 Correct 132 ms 2652 KB Output is correct
3 Correct 130 ms 2652 KB Output is correct
4 Correct 133 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 65 ms 2776 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 32 ms 2652 KB Output is correct
9 Correct 130 ms 2652 KB Output is correct
10 Correct 138 ms 2648 KB Output is correct
11 Correct 16 ms 2652 KB Output is correct
12 Correct 133 ms 2652 KB Output is correct
13 Incorrect 1 ms 2648 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2688 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 20 ms 7004 KB Output is correct
6 Correct 21 ms 7004 KB Output is correct
7 Correct 18 ms 7092 KB Output is correct
8 Correct 19 ms 7004 KB Output is correct
9 Correct 131 ms 2652 KB Output is correct
10 Correct 132 ms 2652 KB Output is correct
11 Correct 130 ms 2652 KB Output is correct
12 Correct 133 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 65 ms 2776 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 32 ms 2652 KB Output is correct
17 Correct 130 ms 2652 KB Output is correct
18 Correct 138 ms 2648 KB Output is correct
19 Correct 16 ms 2652 KB Output is correct
20 Correct 133 ms 2652 KB Output is correct
21 Incorrect 1 ms 2648 KB Output isn't correct
22 Halted 0 ms 0 KB -