# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
253839 |
2020-07-28T21:36:57 Z |
aZvezda |
Pipes (BOI13_pipes) |
C++14 |
|
240 ms |
24300 KB |
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl
const ll MAX_N = 1e5 + 10;
set<pair<ll, ll> > g[MAX_N];
ll ans[MAX_N], arr[MAX_N];
struct cmp {
bool operator ()(const ll &a, const ll &b) const {
if(g[a].size() == g[b].size()) {
return a < b;
}
return g[a].size() < g[b].size();
}
};
multiset<ll, cmp> pq;
void removeBranches() {
while(!pq.empty() && g[*(pq.begin())].size() == 1) {
ll curr = *(pq.begin()); pq.erase(pq.begin());
auto other = *(g[curr].begin());
ans[other.second] = arr[curr];
arr[other.first] -= arr[curr];
g[other.first].erase({curr, other.second});
}
}
signed main() {
//ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll n, m;
cin >> n >> m;
if(m > n) {cout << 0 << endl; return 0;}
for(ll i = 1; i <= n; i ++) {
cin >> arr[i];
}
for(ll i = 0; i < m; i ++) {
ll a, b;
cin >> a >> b;
g[a].insert({b, i});
g[b].insert({a, i});
}
for(ll i = 1; i <= n; i ++) {
pq.insert(i);
}
removeBranches();
for(ll i = 0; i < m; i ++) {
cout << ans[i] * 2 << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
2 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
3 |
Incorrect |
4 ms |
5248 KB |
Output isn't correct |
4 |
Incorrect |
240 ms |
23956 KB |
Output isn't correct |
5 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
7 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
5248 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
5248 KB |
Output isn't correct |
11 |
Incorrect |
6 ms |
5248 KB |
Output isn't correct |
12 |
Incorrect |
6 ms |
5248 KB |
Output isn't correct |
13 |
Incorrect |
180 ms |
20216 KB |
Output isn't correct |
14 |
Incorrect |
219 ms |
23160 KB |
Output isn't correct |
15 |
Incorrect |
230 ms |
24300 KB |
Output isn't correct |
16 |
Incorrect |
219 ms |
21240 KB |
Output isn't correct |
17 |
Incorrect |
227 ms |
24056 KB |
Output isn't correct |
18 |
Incorrect |
235 ms |
24184 KB |
Output isn't correct |
19 |
Incorrect |
200 ms |
24056 KB |
Output isn't correct |
20 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
21 |
Incorrect |
4 ms |
5120 KB |
Output isn't correct |
22 |
Incorrect |
230 ms |
24056 KB |
Output isn't correct |
23 |
Incorrect |
170 ms |
20160 KB |
Output isn't correct |
24 |
Incorrect |
222 ms |
24148 KB |
Output isn't correct |
25 |
Incorrect |
185 ms |
20944 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
5120 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
5376 KB |
Output isn't correct |
3 |
Incorrect |
198 ms |
22904 KB |
Output isn't correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
10 |
Correct |
4 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
3 ms |
4992 KB |
Output is correct |
13 |
Correct |
4 ms |
4992 KB |
Output is correct |
14 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
5248 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
5248 KB |
Output isn't correct |
17 |
Incorrect |
5 ms |
5248 KB |
Output isn't correct |
18 |
Correct |
3 ms |
4992 KB |
Output is correct |
19 |
Correct |
3 ms |
4992 KB |
Output is correct |
20 |
Correct |
5 ms |
4992 KB |
Output is correct |
21 |
Correct |
3 ms |
4992 KB |
Output is correct |
22 |
Incorrect |
5 ms |
5248 KB |
Output isn't correct |
23 |
Incorrect |
165 ms |
20604 KB |
Output isn't correct |
24 |
Incorrect |
207 ms |
24208 KB |
Output isn't correct |
25 |
Incorrect |
199 ms |
22904 KB |
Output isn't correct |
26 |
Correct |
4 ms |
4992 KB |
Output is correct |
27 |
Correct |
3 ms |
4992 KB |
Output is correct |
28 |
Correct |
3 ms |
4992 KB |
Output is correct |
29 |
Correct |
3 ms |
4992 KB |
Output is correct |
30 |
Incorrect |
192 ms |
23672 KB |
Output isn't correct |
31 |
Incorrect |
197 ms |
23932 KB |
Output isn't correct |
32 |
Incorrect |
224 ms |
24060 KB |
Output isn't correct |
33 |
Incorrect |
203 ms |
24056 KB |
Output isn't correct |
34 |
Correct |
3 ms |
4992 KB |
Output is correct |
35 |
Correct |
3 ms |
4992 KB |
Output is correct |
36 |
Correct |
3 ms |
4992 KB |
Output is correct |
37 |
Correct |
3 ms |
4992 KB |
Output is correct |
38 |
Incorrect |
192 ms |
24056 KB |
Output isn't correct |
39 |
Incorrect |
216 ms |
24056 KB |
Output isn't correct |
40 |
Incorrect |
221 ms |
24056 KB |
Output isn't correct |
41 |
Incorrect |
197 ms |
24056 KB |
Output isn't correct |
42 |
Correct |
3 ms |
4992 KB |
Output is correct |
43 |
Correct |
3 ms |
4992 KB |
Output is correct |
44 |
Correct |
4 ms |
4992 KB |
Output is correct |
45 |
Correct |
4 ms |
4992 KB |
Output is correct |
46 |
Incorrect |
188 ms |
23928 KB |
Output isn't correct |
47 |
Incorrect |
222 ms |
24056 KB |
Output isn't correct |
48 |
Incorrect |
195 ms |
24056 KB |
Output isn't correct |
49 |
Incorrect |
203 ms |
23032 KB |
Output isn't correct |
50 |
Correct |
3 ms |
4992 KB |
Output is correct |
51 |
Correct |
3 ms |
4992 KB |
Output is correct |
52 |
Correct |
3 ms |
4992 KB |
Output is correct |
53 |
Correct |
3 ms |
4992 KB |
Output is correct |
54 |
Incorrect |
193 ms |
23800 KB |
Output isn't correct |