Submission #973339

# Submission time Handle Problem Language Result Execution time Memory
973339 2024-05-01T19:05:06 Z Circling Šarenlist (COCI22_sarenlist) C++17
110 / 110
38 ms 468 KB
/*The British Royal Family and a small cadre of English Fabian Socialists, in
conjunction with the Rockefellers and the Rothchilds, are engaged in a
conspiracy to greatly reduce the population of the human race in order to head
off a Malthusian catastrophe, a catastrophe that could easily be avoided by
simply building a massive amount of nuclear power plants and a number of massive
superhighways and bridges to connect all of the world's continents. But doing
that would cut into the conspiracy's profits. So the British Royal Family
invented environmentalism and neoliberalism in order to hide the truth. And in
order to further reduce the population, the British Royal Family is also the
world's foremost drug trafficking conspiracy. And it uses its control of the IMF
to push austerity in order to kill as many people in the global south as
possible.
And also Henry Kissinger is a gay KGB agent. */
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;


int64_t n, m, k, p[61], mod = 1000000007, a, b, edgebm[61], aanc, banc, powmod[60], ans = 0, coeff, grc, dsup[61], dsus[61];
vector<vector<int>> graph;
set<int> apath;


void dfs(int nd, int pr){
    p[nd] = pr;
    for (int i: graph[nd]) if (i != pr) dfs(i, nd);
}


int finddsup(int nd){
    if (dsup[nd] == nd) return nd;
    finddsup(dsup[nd]);
    dsup[nd] = dsup[dsup[nd]];
    return dsup[nd];
}


bool unite(int nda, int ndb){
    int pa = finddsup(nda);
    int pb = finddsup(ndb);
    if (pa == pb) return false;
    if (dsus[pa] > dsus[pb]) swap(pa, pb);
    dsup[pa] = pb;
    dsus[pb] += dsus[pa];
    return true;
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n >> m >> k;
    graph.resize(n + 1);
    for (int i = 1; i < n; i++){
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
        edgebm[i + 1] = 0;
    }
    dfs(1, 0);
    for (int i = 0; i < m; i++){
        cin >> a >> b;
        apath.clear();
        for (aanc = a; aanc != 0; aanc = p[aanc]) apath.insert(aanc);
        for (banc = b; apath.find(banc) == apath.end(); banc = p[banc]);
        for (; a != banc; a = p[a]) edgebm[a] += 1 << i;
        for (; b != banc; b = p[b]) edgebm[b] += 1 << i;
    }
    powmod[0] = 1;
    for (int i = 1; i < n; i++) powmod[i] = (powmod[i - 1] * k) % mod;
    for (int i = 0; i < (1 << m); i++){
        coeff = 1;
        for (int j = 0; j < m; j++) if (((i >> j) & 1) == 1) coeff *= -1;
        grc = n - 1;
        for (int j = 2; j <= n; j++){
            dsup[j] = j;
            dsus[j] = 1;
        }
        for (int e1 = 2; e1 <= n; e1++) for (int e2 = 2; e2 < e1; e2++) if (((edgebm[e1] & edgebm[e2] & i) > 0) && unite(e1, e2)) grc--;
        ans = (ans + coeff * powmod[grc] + mod) % mod;
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 8 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 8 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 34 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 30 ms 344 KB Output is correct
31 Correct 8 ms 344 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 4 ms 348 KB Output is correct
35 Correct 16 ms 468 KB Output is correct
36 Correct 38 ms 452 KB Output is correct
37 Correct 16 ms 348 KB Output is correct