Submission #619917

#TimeUsernameProblemLanguageResultExecution timeMemory
619917errorgornŠarenlist (COCI22_sarenlist)C++17
110 / 110
24 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ii pair<int,int> #define fi first #define se second #define endl '\n' #define puf push_front #define pof pop_front #define pub push_back #define pob pop_back #define lb lower_bound #define ub upper_bound #define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--) #define all(x) (x).begin(),(x).end() #define sz(x) (int) (x).size() mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); const int MOD=1000000007; int qexp(int b,int p){ int res=1; while (p){ if (p&1) res=res*b%MOD; b=b*b%MOD; p>>=1; } return res; } int n,m,k; vector<int> al[65]; vector<int> pos[15]; int pp[65]; int d[65]; void dfs(int i,int p){ pp[i]=p; for (auto it:al[i]){ if (it==p) continue; d[it]=d[i]+1; dfs(it,i); } } struct UFDS{ int p[65]; void reset(){ rep(x,0,65) p[x]=x; } int par(int i){ if (p[i]==i) return i; else return p[i]=par(p[i]); } void unions(int i,int j){ i=par(i),j=par(j); p[i]=j; } } ufds; signed main(){ cin.tie(0); cout.tie(0); cin.sync_with_stdio(false); cin>>n>>m>>k; int a,b; rep(x,1,n){ cin>>a>>b; al[a].pub(b); al[b].pub(a); } dfs(1,-1); rep(x,0,m){ cin>>a>>b; while (a!=b){ if (d[a]<d[b]) swap(a,b); pos[x].pub(a); a=pp[a]; } } //rep(x,0,m){ //for (auto it:pos[x]) cout<<it<<" "; cout<<endl; //} int ans=0; rep(mask,0,1<<m){ ufds.reset(); rep(bit,0,m) if (mask&(1<<bit)){ for (auto it:pos[bit]) ufds.unions(pos[bit][0],it); } int cnt=0; rep(x,2,n+1) if (ufds.p[x]==x) cnt++; cnt=qexp(k,cnt); if (__builtin_parity(mask)) ans=(ans-cnt+MOD)%MOD; else ans=(ans+cnt)%MOD; } cout<<ans<<endl; }
#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...