제출 #1126571

#제출 시각아이디문제언어결과실행 시간메모리
1126571AgageldiPipes (BOI13_pipes)C++20
0 / 100
1097 ms17736 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 <int> v[N], ans; queue <int> q; pair <int,pair<int,int>> p[N]; 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; p[i].ff = x; p[i].ss.ff = y; p[i].ss.ss = 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]); } for(int i = 1;i<=m;i++) { if(p[i].ff==b && p[i].ss.ff==par[b] || p[i].ss.ff==b && p[i].ff==par[b]){ ans.pb(vis[b]); vis[par[b]] -= vis[b]; break; } } } for(auto i:ans) { cout << i << "\n"; } cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...