# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
791326 | Username4132 | Šarenlist (COCI22_sarenlist) | C++14 | 2 ms | 4692 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |