Submission #937635

#TimeUsernameProblemLanguageResultExecution timeMemory
937635WonderfulWhaleDesignated Cities (JOI19_designated_cities)C++17
6 / 100
53 ms604 KiB
#include<bits/stdc++.h> using namespace std; #define int int64_t #define pb push_back #define pii pair<int, int> #define st first #define nd second #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() vector<pii> G[20]; vector<bool> tak[20]; void dfs(int x, int p=-1) { for(int i=0;i<sz(G[x]);i++) { auto [y, c] = G[x][i]; if(y==p) continue; tak[x][i] = true; dfs(y, x); } } pii ans[20]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int S = 0; for(int i=0;i<n-1;i++) { int a, b, c, d; cin >> a >> b >> c >> d; a--, b--; G[a].pb({b, d}); G[b].pb({a, c}); tak[a].pb(0); tak[b].pb(0); S+=c+d; } for(int i=1;i<(1<<n);i++) { for(int j=0;j<n;j++) { fill(all(tak[j]), false); } for(int j=0;j<n;j++) { if(i&(1<<j)) { dfs(j); } } int c = 0; for(int j=0;j<n;j++) { for(int k=0;k<sz(G[j]);k++) { if(tak[j][k]) c += G[j][k].nd; } } int x = __builtin_popcount(i); ans[x] = max(ans[x], {c, i}); } int q; cin >> q; while(q--) { int x; cin >> x; cout << S-ans[x].st << "\n"; } }
#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...