제출 #255581

#제출 시각아이디문제언어결과실행 시간메모리
255581amoo_safarPipes (BOI13_pipes)C++17
74.07 / 100
88 ms16504 KiB
// Zende bad Shoma nasime faghat ! #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " : " << x << '\n' using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; const ll Mod = 1000000007LL; const int N = 2e5 + 10; const ll Inf = 2242545357980376863LL; const ll Log = 30; ll n, m, c[N], ans[N]; vector<pll> G[N]; int mk[N]; void Solve(int u){ mk[u] = 1; for(auto [adj, id] : G[u]){ if(!mk[adj]){ Solve(adj); ans[id] = 2 * c[adj]; c[u] -= c[adj]; } } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; if(m >= n) return cout << "0\n", 0; for(int i = 1; i <= n; i++) cin >> c[i]; ll u, v; for(int i = 1; i <= m; i++){ cin >> u >> v; G[u].pb({v, i}); G[v].pb({u, i}); } if(m == n - 1){ Solve(1); } for(int i = 1; i <= m; i++) cout << ans[i] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...