# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
791326 | 2023-07-24T01:59:44 Z | Username4132 | Šarenlist (COCI22_sarenlist) | C++14 | 2 ms | 4692 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], cur = ed; res[mask] = res[pr] | 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 312 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 852 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 308 KB | Output is correct |
4 | Correct | 1 ms | 308 KB | Output is correct |
5 | Correct | 1 ms | 1364 KB | Output is correct |
6 | Correct | 1 ms | 1364 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 312 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 852 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 1 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 0 ms | 308 KB | Output is correct |
23 | Correct | 1 ms | 308 KB | Output is correct |
24 | Correct | 1 ms | 1364 KB | Output is correct |
25 | Correct | 1 ms | 1364 KB | Output is correct |
26 | Correct | 0 ms | 340 KB | Output is correct |
27 | Correct | 1 ms | 2516 KB | Output is correct |
28 | Correct | 1 ms | 212 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 2552 KB | Output is correct |
31 | Correct | 1 ms | 852 KB | Output is correct |
32 | Correct | 1 ms | 596 KB | Output is correct |
33 | Correct | 0 ms | 340 KB | Output is correct |
34 | Correct | 1 ms | 596 KB | Output is correct |
35 | Correct | 1 ms | 1364 KB | Output is correct |
36 | Correct | 2 ms | 4692 KB | Output is correct |
37 | Correct | 2 ms | 2516 KB | Output is correct |