# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
621355 |
2022-08-03T18:01:24 Z |
353cerega |
Pipes (BOI13_pipes) |
C++17 |
|
109 ms |
16196 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;
for (ll i=0;i!=D-2;i=(i+2)%D)
{
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] << "\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 |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
83 ms |
16076 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
69 ms |
12852 KB |
Output is correct |
14 |
Correct |
88 ms |
15408 KB |
Output is correct |
15 |
Correct |
98 ms |
16196 KB |
Output is correct |
16 |
Correct |
83 ms |
13728 KB |
Output is correct |
17 |
Correct |
88 ms |
16124 KB |
Output is correct |
18 |
Correct |
99 ms |
16196 KB |
Output is correct |
19 |
Correct |
89 ms |
13544 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
109 ms |
16160 KB |
Output is correct |
23 |
Correct |
69 ms |
12840 KB |
Output is correct |
24 |
Correct |
89 ms |
16176 KB |
Output is correct |
25 |
Correct |
75 ms |
13516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
3 |
Correct |
66 ms |
13892 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 |
340 KB |
Output is correct |
7 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
23 |
Incorrect |
78 ms |
13168 KB |
Output isn't correct |
24 |
Incorrect |
89 ms |
15436 KB |
Output isn't correct |
25 |
Correct |
65 ms |
13892 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Incorrect |
81 ms |
14784 KB |
Output isn't correct |
31 |
Incorrect |
86 ms |
15668 KB |
Output isn't correct |
32 |
Incorrect |
103 ms |
15708 KB |
Output isn't correct |
33 |
Correct |
82 ms |
14088 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 |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Incorrect |
84 ms |
15432 KB |
Output isn't correct |
39 |
Incorrect |
94 ms |
15800 KB |
Output isn't correct |
40 |
Incorrect |
79 ms |
15572 KB |
Output isn't correct |
41 |
Correct |
57 ms |
13128 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Incorrect |
78 ms |
14872 KB |
Output isn't correct |
47 |
Incorrect |
83 ms |
15620 KB |
Output isn't correct |
48 |
Incorrect |
69 ms |
15840 KB |
Output isn't correct |
49 |
Correct |
91 ms |
14780 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
54 |
Incorrect |
72 ms |
15300 KB |
Output isn't correct |