Submission #791326

#TimeUsernameProblemLanguageResultExecution timeMemory
791326Username4132Šarenlist (COCI22_sarenlist)C++14
110 / 110
2 ms4692 KiB
#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)

Main.cpp: In function 'int main()':
Main.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:31:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         int a, b; scanf("%d %d", &a, &b); --a, --b;
      |                   ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:35:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         int a, b; scanf("%d %d", &a, &b); --a, --b;
      |                   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...