# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
621363 |
2022-08-03T18:04:20 Z |
353cerega |
Pipes (BOI13_pipes) |
C++17 |
|
136 ms |
16208 KB |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define X first
#define Y second
//const ll mod = 1000000007;
const ll mod = 998244353;
void solve()
{
ll n, m;
cin >> n >> m;
if (m>n)
{
cout << 0 << "\n";
return;
}
vector<ll> a(n);
ll W = 0;
for (ll i=0;i<n;i++)
{
cin >> a[i];
W += a[i];
}
if (W%2!=0)
{
cout << 0 << "\n";
return;
}
vector<ll> b(m), d(n);
vector<pair<ll,ll>> e(m);
vector<vector<ll>> g(n);
for (ll i=0;i<m;i++)
{
ll u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(i);
g[v].push_back(i);
e[i] = {u,v};
d[u]++, d[v]++;
}
vector<ll> was(m), ans(m);
set<ll> kek;
for (ll i=0;i<n;i++) if (d[i]==1) kek.insert(i);
while (kek.size()>0)
{
ll u = *kek.begin();
ll w = a[u];
for (ll p: g[u])
{
if (was[p]==1) continue;
was[p] = 1;
d[e[p].X]--;
if (d[e[p].X]==1) kek.insert(e[p].X);
if (d[e[p].X]==0) kek.erase(e[p].X);
d[e[p].Y]--;
if (d[e[p].Y]==1) kek.insert(e[p].Y);
if (d[e[p].Y]==0) kek.erase(e[p].Y);
a[e[p].X] -= w;
a[e[p].Y] -= w;
ans[p] = w;
}
}
ll D = 0;
for (ll i=0;i<n;i++) if (d[i]==2) D++;
if (D==0)
{
for (ll i=0;i<n;i++)
{
if (a[i]!=0)
{
cout << 0 << "\n";
return;
}
}
for (ll i=0;i<m;i++) cout << ans[i]*2 << "\n";
return;
}
if (D%2==0)
{
cout << 0 << "\n";
return;
}
for (ll st=0;st<n;st++)
{
if (d[st]!=2) continue;
vector<ll> used(n);
ll u = st;
vector<ll> A, B;
ll S = 0;
for (ll k=0;k<D;k++)
{
A.push_back(a[u]);
S += a[u];
for (ll p: g[u])
{
if (was[p]==1) continue;
was[p] = 1;
B.push_back(p);
u = u^e[p].X^e[p].Y;
break;
}
}
S /= 2;
for (ll i=2;i<D;i+=2) S -= A[i];
ll L = 0, R = D-1;
ll Q = D;
for (ll i=0;Q>0;i=(i+2)%D,Q--)
{
ans[B[i]] = S;
L = (L+2)%D;
S += A[L];
R = (R+2)%D;
S -= A[R];
}
for (ll i=0;i<m;i++) cout << ans[i]*2 << "\n";
return;
}
}
int main()
{
ios_base::sync_with_stdio(false);
ll T;
T = 1;
//cin >> T;
while (T--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
121 ms |
16116 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
2 ms |
456 KB |
Output is correct |
10 |
Correct |
2 ms |
452 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
80 ms |
12904 KB |
Output is correct |
14 |
Correct |
100 ms |
15320 KB |
Output is correct |
15 |
Correct |
127 ms |
16184 KB |
Output is correct |
16 |
Correct |
86 ms |
13776 KB |
Output is correct |
17 |
Correct |
118 ms |
16120 KB |
Output is correct |
18 |
Correct |
118 ms |
16180 KB |
Output is correct |
19 |
Correct |
103 ms |
13500 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
134 ms |
16208 KB |
Output is correct |
23 |
Correct |
78 ms |
12920 KB |
Output is correct |
24 |
Correct |
136 ms |
16204 KB |
Output is correct |
25 |
Correct |
105 ms |
13524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
82 ms |
13780 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
456 KB |
Output is correct |
23 |
Correct |
64 ms |
13184 KB |
Output is correct |
24 |
Correct |
93 ms |
15412 KB |
Output is correct |
25 |
Correct |
80 ms |
13872 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
103 ms |
14780 KB |
Output is correct |
31 |
Correct |
85 ms |
15800 KB |
Output is correct |
32 |
Correct |
105 ms |
15632 KB |
Output is correct |
33 |
Correct |
70 ms |
14140 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
99 ms |
15408 KB |
Output is correct |
39 |
Correct |
99 ms |
15840 KB |
Output is correct |
40 |
Correct |
96 ms |
15552 KB |
Output is correct |
41 |
Correct |
56 ms |
13124 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
88 ms |
14800 KB |
Output is correct |
47 |
Correct |
85 ms |
15596 KB |
Output is correct |
48 |
Correct |
82 ms |
15792 KB |
Output is correct |
49 |
Correct |
107 ms |
14764 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Correct |
106 ms |
15304 KB |
Output is correct |