제출 #1127236

#제출 시각아이디문제언어결과실행 시간메모리
1127236AgageldiPipes (BOI13_pipes)C++20
58.52 / 100
738 ms172648 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define N 4000005 #define ff first #define ss second #define pb push_back #define sz(s) (int)s.size() #define rep(c, a, b) for(c = a; c <= b; c++) ll n, m, vis[N], a[N], viss[N]; vector <ll> v[N]; vector <pair <ll,ll>> ans; map <pair<ll,ll>,ll> vip; void solve(int x) { viss[x] = 1; for(auto i : v[x]) { if(viss[i] == 1) continue; solve(i); ans.pb({vip[{x,i}],a[i]}); a[x] -= a[i]; } } int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> n >> m; for(int i = 1;i <= n; i++) { cin >> a[i]; } for(int i = 1;i <= m; i++) { ll x, y; cin >> x >> y; v[x].pb(y); v[y].pb(x); vip[{x,y}] = i; vip[{y,x}] = i; } if(n < m) { cout << '0' << '\n'; return 0; } solve(1); sort(ans.begin(),ans.end()); for(auto i:ans) { cout << i.ss * 2 << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...