Submission #767603

# Submission time Handle Problem Language Result Execution time Memory
767603 2023-06-26T22:31:41 Z shezitt Logičari (COCI21_logicari) C++14
10 / 110
141 ms 5796 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define gcd(a, b) __gcd(a, b)
#define lcm(a,b) a*b/gcd(a,b)
#define pb push_back
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define F first
#define S second
#define sz(x) (int)x.size()
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fore(a, b, c) for(int a=b; a<c; ++a)
#define all(x) x.begin(), x.end()
#define endl '\n';

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#define raya cerr << "==========================" << endl;

const double EPS = 1e-7;
const double PI = acos(-1);
const int MOD = 1e9+7;  
int TC = 1;

const int N = 1e5+5;
vi adj[N];

int main(){
    fast;
    int n;
    cin >> n;
    fore(i, 0, n){
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int ans = 1e9;
    auto check = [&](vector<bool>& blue) -> bool {
        bool ok = 1;
        int r;
        for(int u=0; u<n; ++u){
            r = 0;
            for(int v : adj[u]){
                if(blue[v]){
                    r++;
                }
            }
            ok &= r == 1;
        }
        return ok;
    };  
    for(int mask=1; mask<(1<<n); ++mask){
        vector<bool> blue(n);
        for(int i=0; (1<<i)<=mask; ++i){
            if((1<<i) & mask){
                blue[i] = 1;
            }
        }
        if(check(blue)){
            ans = min(ans, __builtin_popcount(mask));
        }
    }
    cout << (ans == 1e9 ? -1 : ans);
}
 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Incorrect 31 ms 5796 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 135 ms 2644 KB Output is correct
2 Correct 135 ms 2648 KB Output is correct
3 Correct 134 ms 2652 KB Output is correct
4 Correct 134 ms 2648 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 67 ms 2652 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 36 ms 2644 KB Output is correct
9 Correct 139 ms 2644 KB Output is correct
10 Correct 141 ms 2652 KB Output is correct
11 Correct 17 ms 2644 KB Output is correct
12 Correct 133 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 2644 KB Output is correct
2 Correct 135 ms 2648 KB Output is correct
3 Correct 134 ms 2652 KB Output is correct
4 Correct 134 ms 2648 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 67 ms 2652 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 36 ms 2644 KB Output is correct
9 Correct 139 ms 2644 KB Output is correct
10 Correct 141 ms 2652 KB Output is correct
11 Correct 17 ms 2644 KB Output is correct
12 Correct 133 ms 2648 KB Output is correct
13 Incorrect 2 ms 2656 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Incorrect 31 ms 5796 KB Output isn't correct
6 Halted 0 ms 0 KB -