# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
791320 | 2023-07-24T01:39:28 Z | Username4132 | Šarenlist (COCI22_sarenlist) | C++14 | 1 ms | 340 KB |
#include<iostream> #include<vector> #include<algorithm> using namespace std; using pii = pair<int, int>; using ll = long long; #define forn(i, n) for(int i=0; i<(int)n; ++i) #define forsn(i, s, n) for(int i=s; i<(int)n; ++i) #define PB push_back #define F first #define S second const int PO = 1<<15, MOD = 1000000007; ll bit[16]; int n, m, k; pii par[62]; vector<pii> g[62]; int siz[PO]; ll cmp[PO][16], res[PO], pot[62]; void dfs(int v, int p){ for(pii to:g[v]) if(to.F!=p){ par[to.F]={v, to.S}; dfs(to.F, v); } } int main(){ scanf("%d %d %d", &n, &m, &k); forn(i, n-1){ int a, b; scanf("%d %d", &a, &b); --a, --b; g[a].PB({b, i}), g[b].PB({a, i}); } forn(i, m){ int a, b; scanf("%d %d", &a, &b); --a, --b; dfs(a, a); while(b!=a){ bit[i]|=(1LL << (par[b].S)); b=par[b].F; } } pot[0]=1; forn(i, n) pot[i+1]=(pot[i]*k)%MOD; ll ans=pot[n-1]; forsn(mask, 1, (1<<m)){ int ind = __builtin_ctz(mask); int pr = mask - (1 << ind); ll ed = bit[ind]; res[mask] = res[pr] | ed; ll cur=ed; forn(i, siz[pr]){ if(cmp[pr][i] | ed) cur|=cmp[pr][i]; else cmp[mask][siz[mask]++]=cmp[pr][i]; } cmp[mask][siz[mask]++]=cur; int choice = siz[mask] + (n-1-__builtin_popcountll(res[mask])); int add = (__builtin_popcount(mask)&1)? -pot[choice] : pot[choice]; ans = (ans + add + MOD)%MOD; } printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 288 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 312 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Incorrect | 0 ms | 212 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Incorrect | 0 ms | 340 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 288 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 312 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Incorrect | 0 ms | 212 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |