제출 #1126576

#제출 시각아이디문제언어결과실행 시간메모리
1126576AgageldiPipes (BOI13_pipes)C++20
44.07 / 100
762 ms66504 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define N 400005 #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, t, a[N],m, vis[N], out[N], par[N]; vector <pair<int,int>> ans; queue <int> q; map <pair<int,int>,int> vip; int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> n >> m; for(int i = 1;i <= n; i++) { cin >> a[i]; vis[i] = a[i]; } for(int i = 1;i <= m; i++) { int x, y; cin >> x >> y; out[x]++; par[y] = x; vip[{x,y}] = i; vip[{y,x}] = i; } for(int i = 1; i <= n; i++) { if(!out[i]) q.push(i); } while(!q.empty()) { int b = q.front(); q.pop(); out[par[b]]--; if(!out[par[b]]) q.push(par[b]); ans.pb({vip[{b,par[b]}],vis[b]}); vis[par[b]] -= vis[b]; } cout << '0' << '\n'; return 0; sort(ans.begin(),ans.end()); for(int i = 1; i < sz(ans); i++) { cout << ans[i].ss * 2 << "\n"; } cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...