Submission #1091937

#TimeUsernameProblemLanguageResultExecution timeMemory
1091937YassirSalamaDesignated Cities (JOI19_designated_cities)C++17
6 / 100
57 ms604 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define int long long #define F first #define S second const int maxn=26+10; vector<int> v[maxn]; int mp[maxn][maxn]; bool calc[maxn][maxn]; void dfs(int node,int par){ for(auto x:v[node]){ if(x==par) continue; calc[x][node]=1; dfs(x,node); } } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n; cin>>n; vector<pair<int,int>> ed; for(int i=1;i<n;i++){ int a,b,c,d; cin>>a>>b>>c>>d;a--,b--; ed.pb({a,b}); mp[a][b]=c; mp[b][a]=d; v[a].pb(b); v[b].pb(a); } int dp[n+1];for(int i=0;i<=n;i++) dp[i]=1e18; for(int mask=0;mask<(1LL<<n);mask++){ vector<int> r; for(int i=0;i<n;i++){ if((1LL<<i)&mask) r.push_back(i); } memset(calc,0,sizeof(calc)); for(auto x:r){ dfs(x,x); } int ans=0; for(auto x:ed){ if(!calc[x.F][x.S]) ans+=mp[x.F][x.S]; if(!calc[x.S][x.F]){ ans+=mp[x.S][x.F]; } } dp[r.size()]=min(dp[r.size()],ans); } int q; cin>>q; while(q--){ int t; cin>>t; cout<<dp[t]<<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...
#Verdict Execution timeMemoryGrader output
Fetching results...