Submission #542507

#TimeUsernameProblemLanguageResultExecution timeMemory
542507inksamuraiŠarenlist (COCI22_sarenlist)C++17
10 / 110
1 ms328 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define rng(i,x,n) for(int i=x;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define vec(...) vector<__VA_ARGS__> #define _3wByxeT ios::sync_with_stdio(0),cin.tie(0) typedef long long ll; using pii=pair<int,int>; using vi=vector<int>; void print(){cout<<'\n';} template<class h,class...t> void print(const h&v,const t&...u){cout<<v<<' ',print(u...);} // e //snuke's mod int template <ll mod> struct modint{ ll x; // typedef long long ll; modint(ll x=0):x((x%mod+mod)%mod){} modint operator-()const{return modint(-x);} modint& operator+=(const modint a){if((x+=a.x)>=mod) x-=mod; return *this;} modint& operator-=(const modint a){if((x+=mod-a.x)>=mod) x-=mod; return *this;} modint& operator*=(const modint a){(x*=a.x)%=mod; return *this;} modint operator+(const modint a)const{modint res(*this); return res+=a;} modint operator-(const modint a)const{modint res(*this); return res-=a;} modint operator*(const modint a)const{modint res(*this); return res*=a;} modint pow(ll n)const{ modint res=1,x(*this); while(n){ if(n&1)res*=x; x*=x; n>>=1; } return res; } modint inv()const{return pow(mod-2);} }; using mint=modint<1000'000'007>; signed main(){ _3wByxeT; int n,m,k; cin>>n>>m>>k; vec(vi) adj(n); rep(i,n-1){ int u,v; cin>>u>>v; u-=1,v-=1; adj[u].pb(v); adj[v].pb(u); } using vp=vec(pii); vp es; rep(i,m){ int u,v; cin>>u>>v; u-=1,v-=1; es.pb({u,v}); } mint ans=0; rep(msk,(1<<m)){ std::map<pii,int> mp; auto dfs=[&](auto self,int v,int par,int nd)->bool{ if(v==nd) return 1; bool sok=0; for(auto u:adj[v]){ if(u==par) continue; bool pok=self(self,u,v,nd); if(pok) mp[minmax(u,v)]=1; sok=sok or pok; } return sok; }; auto add=[&](int u,int v){ dfs(dfs,v,-1,u); }; rep(i,m){ if(msk>>i&1){ auto [u,v]=es[i]; add(u,v); } } int now=sz(mp); if(__builtin_popcount(msk)%2){ ans-=mint(k)*mint(k).pow(n-1-now); }else{ if(msk){ ans+=mint(k)*mint(k).pow(n-1-now); }else{ ans+=mint(k).pow(n-1); } } } print(ans.x); // return 0; }
#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...