Submission #556258

#TimeUsernameProblemLanguageResultExecution timeMemory
556258new_accŠarenlist (COCI22_sarenlist)C++14
110 / 110
27 ms348 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pitem item* using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; const int N=100; const int M=16; const int SS=1<<19; const int INFi=2e9; const ll INFl=1e13; const ll mod2=998244353; const ll mod=1e9+7; const ll mod3=1000696969; const ll p=70032301; const ull p2=913; const int L=20; int dp[(1<<M)+10],fau[N],dep[N],val[N],oj[N]; ll pot[N]; vector<pair<int,int> >graf[N]; bitset<N>vis; pair<int,int> w[N]; int Find(int a){ if(fau[a]==a) return a; return fau[a]=Find(fau[a]); } void Union(int a,int b){ fau[Find(a)]=Find(fau[b]); } void dfs(int v,int o){ for(auto [u,id]:graf[v]){ if(u==o) continue; oj[u]=v,val[u]=id; dep[u]=dep[v]+1; dfs(u,v); } } void solve(){ int n,m; ll k; cin>>n>>m>>k; pot[0]=1; for(int i=1;i<=n;i++) pot[i]=(pot[i-1]*k)%mod; for(int a,b,i=1;i<n;i++){ cin>>a>>b; graf[a].push_back({b,i}),graf[b].push_back({a,i}); } dfs(1,1); for(int i=1;i<=m;i++) cin>>w[i].fi>>w[i].se; ll res=pot[n-1]; for(int i=1;i<(1<<m);i++){ for(int i=1;i<n;i++) fau[i]=i; for(int j=0;j<m;j++){ if((1<<j)&i){ int a=w[j+1].fi,b=w[j+1].se,pop=0; while(a!=b){ if(dep[a]<dep[b]) swap(a,b); if(pop!=0) Union(pop,val[a]); else pop=val[a]; a=oj[a]; } } } vis.reset(); int curr=0; for(int j=1;j<n;j++){ if(!vis[Find(j)]){ curr++; vis[Find(j)]=1; } } ll akt=pot[curr]*(__builtin_popcount(i)&1?-1:1); (res+=akt+mod)%=mod; } cout<<res<<"\n"; } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); int tt=1; while(tt--) solve(); }

Compilation message (stderr)

Main.cpp: In function 'void dfs(int, int)':
Main.cpp:34:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |     for(auto [u,id]:graf[v]){
      |              ^
#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...