답안 #879246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879246 2023-11-27T03:11:44 Z vjudge1 Logičari (COCI21_logicari) C++17
20 / 110
23 ms 2808 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10, MOD = 998244353;

bool is[N];
vector<int> g[N];
int check(int n){
    int res = 1e9;
    for(int i = 0;i < (1 << n);i++){
        for(int j = 0;j < n;j++){
            if((i >> j) & 1){
                is[j + 1] = 1;
            }else{
                is[j + 1] = 0;
            }
        }
        bool ok = true;
        for(int j = 1;j <= n;j++){
            int x = 0;
            for(int to:g[j]){
                x += is[to];
            }
            if(x != 1){
                ok = false;
                break;
            }
        }
        if(ok){
            res = min(res,__builtin_popcount(i));
        }
    }
    if(res == 1e9) res = -1;
    return res;
}
int n;
void solve(){
    for(int i = 1;i <= n;i++){
        int x,y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int res = check(n);
    if(res == -1){
        cout << res;
        return;
    }
    assert((n / 2) - res >= 0);
    cout << res;
}
void test(){
    cin >> n;
    if(n <= 20){
        solve();
        return;
    }
    if(n % 4){
        cout << -1;
        return;
    }
    cout << n / 2;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    // cin >> T;
    for(int i = 1;i <= T;i++)
    {
        test();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2652 KB Output is correct
2 Correct 16 ms 2652 KB Output is correct
3 Correct 16 ms 2652 KB Output is correct
4 Correct 17 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 8 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 4 ms 2652 KB Output is correct
9 Correct 23 ms 2808 KB Output is correct
10 Correct 19 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 18 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2652 KB Output is correct
2 Correct 16 ms 2652 KB Output is correct
3 Correct 16 ms 2652 KB Output is correct
4 Correct 17 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 8 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 4 ms 2652 KB Output is correct
9 Correct 23 ms 2808 KB Output is correct
10 Correct 19 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 18 ms 2808 KB Output is correct
13 Incorrect 1 ms 2652 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 15 ms 2652 KB Output is correct
10 Correct 16 ms 2652 KB Output is correct
11 Correct 16 ms 2652 KB Output is correct
12 Correct 17 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 8 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 23 ms 2808 KB Output is correct
18 Correct 19 ms 2652 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 18 ms 2808 KB Output is correct
21 Incorrect 1 ms 2652 KB Output isn't correct
22 Halted 0 ms 0 KB -