#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
ll const N = 1e5 + 9;
ll C[N], C2[N], X[N];
bool odw[N];
vector<ll> G[N];
bool t = true;
map<pair<ll, ll>, ll> M;
pair<ll, ll> T[N];
void dfs(ll v) {
odw[v] = 1;
bool k = true;
for (ll i = 0; i < G[v].size(); i++) {
ll syn = G[v][i];
if (odw[syn] == 0) {
dfs(syn);
C2[v] += C[syn];
M[{v, syn}] = C[syn] * 2;
M[{syn, v}] = C[syn] * 2;
k = false;
}
}
if (k == true) C2[v] = C[v];
}
void task1(ll n, ll m) {
dfs(1);
for (ll i = 0; i < n; i++) {
if (C[i] != C2[i]) {
cout << "0\n";
return;
}
}
for (ll i = 0; i < m; i++) {
cout << M[T[i]] << "\n";
}
return;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, m;
cin >> n >> m;
for (ll i = 1; i <= n; i++)
cin >> C[i];
for (ll i = 0; i < m; i++) {
ll a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
T[i] = { a, b };
}
task1(n, m); //podzadanie za 30
}
Compilation message
pipes.cpp: In function 'void dfs(ll)':
pipes.cpp:18:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (ll i = 0; i < G[v].size(); i++) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
2764 KB |
Output isn't correct |
4 |
Incorrect |
168 ms |
22040 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
2636 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
2764 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
2764 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
2764 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
2892 KB |
Output isn't correct |
13 |
Incorrect |
127 ms |
18124 KB |
Output isn't correct |
14 |
Incorrect |
168 ms |
20932 KB |
Output isn't correct |
15 |
Incorrect |
175 ms |
22132 KB |
Output isn't correct |
16 |
Incorrect |
142 ms |
19128 KB |
Output isn't correct |
17 |
Incorrect |
174 ms |
22084 KB |
Output isn't correct |
18 |
Incorrect |
180 ms |
22164 KB |
Output isn't correct |
19 |
Incorrect |
172 ms |
28440 KB |
Output isn't correct |
20 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
21 |
Incorrect |
2 ms |
2764 KB |
Output isn't correct |
22 |
Incorrect |
200 ms |
22132 KB |
Output isn't correct |
23 |
Incorrect |
119 ms |
17988 KB |
Output isn't correct |
24 |
Incorrect |
165 ms |
22116 KB |
Output isn't correct |
25 |
Incorrect |
148 ms |
18876 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
2892 KB |
Output isn't correct |
3 |
Correct |
166 ms |
26932 KB |
Output is correct |
4 |
Correct |
188 ms |
32212 KB |
Output is correct |
5 |
Correct |
173 ms |
21828 KB |
Output is correct |
6 |
Runtime error |
55 ms |
17552 KB |
Execution killed with signal 11 |
7 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
2636 KB |
Output isn't correct |
9 |
Correct |
1 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
1 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Incorrect |
2 ms |
2636 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
2892 KB |
Output isn't correct |
16 |
Incorrect |
4 ms |
2892 KB |
Output isn't correct |
17 |
Correct |
2 ms |
2892 KB |
Output is correct |
18 |
Correct |
2 ms |
2892 KB |
Output is correct |
19 |
Correct |
3 ms |
2892 KB |
Output is correct |
20 |
Correct |
3 ms |
2764 KB |
Output is correct |
21 |
Correct |
3 ms |
2892 KB |
Output is correct |
22 |
Incorrect |
2 ms |
2892 KB |
Output isn't correct |
23 |
Incorrect |
118 ms |
25412 KB |
Output isn't correct |
24 |
Incorrect |
170 ms |
29220 KB |
Output isn't correct |
25 |
Correct |
162 ms |
26972 KB |
Output is correct |
26 |
Correct |
185 ms |
30916 KB |
Output is correct |
27 |
Correct |
170 ms |
31740 KB |
Output is correct |
28 |
Runtime error |
49 ms |
17344 KB |
Execution killed with signal 11 |
29 |
Runtime error |
52 ms |
17932 KB |
Execution killed with signal 11 |
30 |
Incorrect |
175 ms |
33420 KB |
Output isn't correct |
31 |
Incorrect |
169 ms |
33860 KB |
Output isn't correct |
32 |
Incorrect |
162 ms |
24488 KB |
Output isn't correct |
33 |
Correct |
183 ms |
29508 KB |
Output is correct |
34 |
Correct |
159 ms |
29640 KB |
Output is correct |
35 |
Correct |
199 ms |
32288 KB |
Output is correct |
36 |
Runtime error |
57 ms |
17092 KB |
Execution killed with signal 11 |
37 |
Runtime error |
63 ms |
17508 KB |
Execution killed with signal 11 |
38 |
Incorrect |
160 ms |
31988 KB |
Output isn't correct |
39 |
Incorrect |
178 ms |
23344 KB |
Output isn't correct |
40 |
Incorrect |
188 ms |
28592 KB |
Output isn't correct |
41 |
Correct |
161 ms |
33772 KB |
Output is correct |
42 |
Correct |
167 ms |
30404 KB |
Output is correct |
43 |
Correct |
170 ms |
33132 KB |
Output is correct |
44 |
Correct |
170 ms |
21728 KB |
Output is correct |
45 |
Runtime error |
49 ms |
15796 KB |
Execution killed with signal 11 |
46 |
Incorrect |
157 ms |
34968 KB |
Output isn't correct |
47 |
Incorrect |
158 ms |
28740 KB |
Output isn't correct |
48 |
Incorrect |
172 ms |
33572 KB |
Output isn't correct |
49 |
Correct |
169 ms |
22876 KB |
Output is correct |
50 |
Correct |
185 ms |
29716 KB |
Output is correct |
51 |
Correct |
180 ms |
26324 KB |
Output is correct |
52 |
Correct |
175 ms |
24900 KB |
Output is correct |
53 |
Runtime error |
54 ms |
16196 KB |
Execution killed with signal 11 |
54 |
Incorrect |
165 ms |
30852 KB |
Output isn't correct |