Submission #699538

#TimeUsernameProblemLanguageResultExecution timeMemory
699538Dan4LifeElection Campaign (JOI15_election_campaign)C++17
0 / 100
1087 ms16808 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll // delete if causing problems #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define mod(a) (a+MOD)%MOD #define all(a) a.begin(), a.end() #define sz(a) (int)a.size() const int mxN = (int)3e5+10; // change when needed! int n, m, a[mxN], b[mxN], c[mxN], vis[mxN]; vector<int> adj[mxN]; bool dfs(int s, int t, int p){ if(s==t) return true; for(auto u : adj[s]){ if(u==p) continue; if(dfs(u,t,s)){ vis[u]++; return true; } } return false; } void solve() { cin >> n; int ans = 0; for(int i = 1; i < n; i++){ int a, b; cin >> a >> b; adj[a].pb(b), adj[b].pb(a); } cin >> m; for(int i = 0; i < m; i++){ cin >> a[i] >> b[i] >> c[i]; } for(int mask = 0; mask < (1<<m); mask++){ int tot = 0; fill(vis,vis+n+1,0); for(int i = 0; i < m; i++) if((mask>>i)&1) tot+=c[i], vis[a[i]]++, dfs(a[i],b[i], -1); bool ok = 1; for(int i = 1; i <= n; i++) if(vis[i]>1) ok=0; if(ok) ans = max(ans, tot); } cout << ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; //cin >> t; while(t--) solve(); }
#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...