Submission #1336551

#TimeUsernameProblemLanguageResultExecution timeMemory
1336551doantaolaaidiGeppetto (COCI15_geppetto)C++20
0 / 80
1 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define AC "test"
#define foru(i, l, r) for (int i = (l); i <= (r); i++)
#define ford(i, l, r) for (int i = (l); i >= (r); i--)
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;

const ll inf = 1e9 + 7;
const ll linf = 1e18 + 7;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 7;
const int base = 31;

void fastIO(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

ll mul(ll a, ll b){
    a%=mod;
    ll res = 0;
    while (b){
        if (b%2) res = (res + a)%mod;
        a = (a + a)%mod;
        b/=2;
    }
    return res;
}

ll Pow(ll a, ll b){
    ll ans = 1;
    while (b){
        if (b % 2) ans = mul(ans, a);
        a = mul(a, a);
        b/=2;
    }
    return ans;
}

ll n, q, a, b, res, val[22][22], par[maxn], sz[maxn];
vector<pll> e;

int get(int s){
    return (s == par[s] ? s : par[s] = get(par[s]));
}

void uni(int u, int v){
    u = get(u);
    v = get(v);
    if (v == u) return;
    if (sz[u] < sz[v]) swap(u, v);
    par[v] = u;
    res += ((1 << sz[u]) - 1) * ((1 << sz[v]) - 1);
    sz[u] += sz[v];
}

void solve(){
    cin >> n >> q;
    foru(i, 1, n){
        par[i] = i;
        sz[i] = 1;
    }
    foru(i, 1, n) foru(j, i + 1, n) val[i][j] = 1;
    while (q--){
        cin >> a >> b;
        val[a][b] = 0;
    }
    foru(i, 1, n){
        foru(j, i + 1, n){
            if (val[i][j]) e.pb(make_pair(i, j));
        }
    }
    res = n + 1;
    for (pll tmp : e){
        uni(tmp.fi, tmp.se);
    }
    cout << res;
}

int main(){
    fastIO();
    if (fopen(AC".inp", "r")){
        freopen(AC".inp", "r", stdin);
        freopen(AC".out", "w", stdout);
    }
    solve();
}

Compilation message (stderr)

geppetto.cpp: In function 'int main()':
geppetto.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(AC".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
geppetto.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(AC".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...