#include <iostream>
#include <vector>
#include <map>
using namespace std;
int const N = 1e5 + 9;
int C[N], C2[N], X[N];
bool odw[N];
vector<int> G[N];
bool t = true;
map<pair<int, int>, int> M;
pair<int, int> T[N];
void dfs(int v) {
odw[v] = 1;
bool k = true;
for (int i = 0; i < G[v].size(); i++) {
int 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(int n, int m) {
dfs(1);
for (int i = 0; i < n; i++) {
if (C[i] != C2[i]) {
cout << "0\n";
return;
}
}
for (int i = 0; i < m; i++) {
cout << M[T[i]] << "\n";
}
return;
}
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> C[i];
for (int i = 0; i < m; i++) {
int 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(int)':
pipes.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < G[v].size(); i++) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2664 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
2768 KB |
Output isn't correct |
4 |
Incorrect |
220 ms |
21500 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
2768 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
2768 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
2768 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
2924 KB |
Output isn't correct |
13 |
Incorrect |
177 ms |
17656 KB |
Output isn't correct |
14 |
Incorrect |
233 ms |
20520 KB |
Output isn't correct |
15 |
Incorrect |
223 ms |
21568 KB |
Output isn't correct |
16 |
Incorrect |
186 ms |
18756 KB |
Output isn't correct |
17 |
Incorrect |
243 ms |
21512 KB |
Output isn't correct |
18 |
Incorrect |
228 ms |
21576 KB |
Output isn't correct |
19 |
Incorrect |
253 ms |
27564 KB |
Output isn't correct |
20 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
21 |
Incorrect |
3 ms |
2768 KB |
Output isn't correct |
22 |
Incorrect |
226 ms |
21624 KB |
Output isn't correct |
23 |
Incorrect |
181 ms |
17664 KB |
Output isn't correct |
24 |
Incorrect |
234 ms |
21520 KB |
Output isn't correct |
25 |
Incorrect |
166 ms |
18396 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
2924 KB |
Output isn't correct |
3 |
Correct |
238 ms |
25976 KB |
Output is correct |
4 |
Correct |
242 ms |
31084 KB |
Output is correct |
5 |
Correct |
234 ms |
21408 KB |
Output is correct |
6 |
Runtime error |
150 ms |
16584 KB |
Execution killed with signal 6 |
7 |
Incorrect |
2 ms |
2664 KB |
Output isn't correct |
8 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
15 |
Incorrect |
3 ms |
2920 KB |
Output isn't correct |
16 |
Incorrect |
4 ms |
2768 KB |
Output isn't correct |
17 |
Correct |
3 ms |
2896 KB |
Output is correct |
18 |
Correct |
3 ms |
2796 KB |
Output is correct |
19 |
Correct |
3 ms |
2896 KB |
Output is correct |
20 |
Correct |
3 ms |
2768 KB |
Output is correct |
21 |
Correct |
4 ms |
2896 KB |
Output is correct |
22 |
Incorrect |
3 ms |
2896 KB |
Output isn't correct |
23 |
Incorrect |
175 ms |
24420 KB |
Output isn't correct |
24 |
Incorrect |
239 ms |
28188 KB |
Output isn't correct |
25 |
Correct |
219 ms |
25952 KB |
Output is correct |
26 |
Correct |
229 ms |
29816 KB |
Output is correct |
27 |
Correct |
265 ms |
30536 KB |
Output is correct |
28 |
Runtime error |
117 ms |
15560 KB |
Execution killed with signal 11 |
29 |
Runtime error |
164 ms |
17356 KB |
Execution killed with signal 6 |
30 |
Incorrect |
232 ms |
31976 KB |
Output isn't correct |
31 |
Incorrect |
237 ms |
32444 KB |
Output isn't correct |
32 |
Incorrect |
232 ms |
23756 KB |
Output isn't correct |
33 |
Correct |
230 ms |
28452 KB |
Output is correct |
34 |
Correct |
265 ms |
28728 KB |
Output is correct |
35 |
Correct |
239 ms |
31024 KB |
Output is correct |
36 |
Runtime error |
109 ms |
15544 KB |
Execution killed with signal 11 |
37 |
Runtime error |
202 ms |
16576 KB |
Execution killed with signal 6 |
38 |
Incorrect |
209 ms |
30720 KB |
Output isn't correct |
39 |
Incorrect |
247 ms |
22728 KB |
Output isn't correct |
40 |
Incorrect |
231 ms |
27556 KB |
Output isn't correct |
41 |
Correct |
217 ms |
32376 KB |
Output is correct |
42 |
Correct |
246 ms |
29468 KB |
Output is correct |
43 |
Correct |
238 ms |
31808 KB |
Output is correct |
44 |
Correct |
213 ms |
21420 KB |
Output is correct |
45 |
Runtime error |
107 ms |
13568 KB |
Execution killed with signal 11 |
46 |
Incorrect |
231 ms |
33440 KB |
Output isn't correct |
47 |
Incorrect |
248 ms |
27720 KB |
Output isn't correct |
48 |
Incorrect |
232 ms |
32064 KB |
Output isn't correct |
49 |
Correct |
218 ms |
22196 KB |
Output is correct |
50 |
Correct |
240 ms |
28640 KB |
Output is correct |
51 |
Correct |
239 ms |
25512 KB |
Output is correct |
52 |
Correct |
242 ms |
24344 KB |
Output is correct |
53 |
Runtime error |
125 ms |
14484 KB |
Execution killed with signal 6 |
54 |
Incorrect |
256 ms |
29684 KB |
Output isn't correct |