#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
const int maxm = 5e5 + 10;
vector<int> grafo[maxn];
int n;
int s[maxn];
map<pair<int, int>, int> mapa;
int val[maxn], ans[maxn];
namespace tree{
int nivel[maxn], pai[maxn], soma[maxn];
void dfs(int u, int p = 0) {
pai[u] = p;
for(auto v : grafo[u]) {
if(v == p) continue;
nivel[v] = nivel[u] + 1;
dfs(v, u);
}
}
};
int main() {
int m;
cin >> n >> m;
// if(m > n) {
// cout << "0\n";
// return 0;
// }
int total = 0;
for(int i=1;i<=n;i++)
cin >> s[i], total += s[i];
for(int i=1;i<=m;i++) {
int a, b;
cin >> a >> b;
grafo[a].push_back(b);
grafo[a].push_back(b);
mapa[{a, b}] = i;
mapa[{b, a}] = i;
}
if(n - 1 == m) {
tree::dfs(1);
vector<pii> arr;
for(int i=1;i<=n;i++)
arr.push_back({tree::nivel[i], i});
sort(arr.begin(), arr.end(), greater<pii>());
for(auto e : arr) {
int v = e.second, u = tree::pai[v];
tree::soma[u] += (s[v] - tree::soma[v]);
ans[mapa[{u, v}]] = (s[v] - tree::soma[v]);
}
for(int i=1;i<=m;i++)
cout << 2*ans[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
2 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
3 |
Incorrect |
5 ms |
2944 KB |
Output isn't correct |
4 |
Incorrect |
253 ms |
25068 KB |
Output isn't correct |
5 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
6 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
7 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
2944 KB |
Output isn't correct |
10 |
Incorrect |
5 ms |
2944 KB |
Output isn't correct |
11 |
Incorrect |
5 ms |
2944 KB |
Output isn't correct |
12 |
Incorrect |
5 ms |
2944 KB |
Output isn't correct |
13 |
Incorrect |
209 ms |
20628 KB |
Output isn't correct |
14 |
Incorrect |
261 ms |
23660 KB |
Output isn't correct |
15 |
Incorrect |
280 ms |
25068 KB |
Output isn't correct |
16 |
Incorrect |
228 ms |
21780 KB |
Output isn't correct |
17 |
Incorrect |
264 ms |
25020 KB |
Output isn't correct |
18 |
Incorrect |
263 ms |
25244 KB |
Output isn't correct |
19 |
Incorrect |
268 ms |
25072 KB |
Output isn't correct |
20 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
21 |
Incorrect |
5 ms |
2944 KB |
Output isn't correct |
22 |
Incorrect |
259 ms |
25044 KB |
Output isn't correct |
23 |
Incorrect |
206 ms |
20368 KB |
Output isn't correct |
24 |
Incorrect |
271 ms |
24944 KB |
Output isn't correct |
25 |
Incorrect |
210 ms |
21352 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
2944 KB |
Output isn't correct |
3 |
Incorrect |
214 ms |
16880 KB |
Output isn't correct |
4 |
Incorrect |
223 ms |
19292 KB |
Output isn't correct |
5 |
Incorrect |
227 ms |
18808 KB |
Output isn't correct |
6 |
Execution timed out |
1066 ms |
71072 KB |
Time limit exceeded |
7 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
2688 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
2732 KB |
Output isn't correct |
13 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
14 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
2816 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
2816 KB |
Output isn't correct |
17 |
Incorrect |
5 ms |
2816 KB |
Output isn't correct |
18 |
Incorrect |
5 ms |
2816 KB |
Output isn't correct |
19 |
Incorrect |
6 ms |
2816 KB |
Output isn't correct |
20 |
Incorrect |
5 ms |
2816 KB |
Output isn't correct |
21 |
Incorrect |
7 ms |
3072 KB |
Output isn't correct |
22 |
Incorrect |
5 ms |
2816 KB |
Output isn't correct |
23 |
Incorrect |
174 ms |
14972 KB |
Output isn't correct |
24 |
Incorrect |
210 ms |
17656 KB |
Output isn't correct |
25 |
Incorrect |
193 ms |
16868 KB |
Output isn't correct |
26 |
Incorrect |
217 ms |
19208 KB |
Output isn't correct |
27 |
Incorrect |
219 ms |
19064 KB |
Output isn't correct |
28 |
Incorrect |
251 ms |
20088 KB |
Output isn't correct |
29 |
Execution timed out |
1018 ms |
63992 KB |
Time limit exceeded |
30 |
Incorrect |
216 ms |
17520 KB |
Output isn't correct |
31 |
Incorrect |
225 ms |
17644 KB |
Output isn't correct |
32 |
Incorrect |
228 ms |
17664 KB |
Output isn't correct |
33 |
Incorrect |
233 ms |
17772 KB |
Output isn't correct |
34 |
Incorrect |
240 ms |
19192 KB |
Output isn't correct |
35 |
Incorrect |
226 ms |
19204 KB |
Output isn't correct |
36 |
Incorrect |
231 ms |
19576 KB |
Output isn't correct |
37 |
Execution timed out |
1075 ms |
74552 KB |
Time limit exceeded |
38 |
Incorrect |
211 ms |
17784 KB |
Output isn't correct |
39 |
Incorrect |
216 ms |
17576 KB |
Output isn't correct |
40 |
Incorrect |
221 ms |
17656 KB |
Output isn't correct |
41 |
Incorrect |
208 ms |
17652 KB |
Output isn't correct |
42 |
Incorrect |
207 ms |
19192 KB |
Output isn't correct |
43 |
Incorrect |
210 ms |
19320 KB |
Output isn't correct |
44 |
Incorrect |
223 ms |
18808 KB |
Output isn't correct |
45 |
Execution timed out |
1077 ms |
69496 KB |
Time limit exceeded |
46 |
Incorrect |
226 ms |
17692 KB |
Output isn't correct |
47 |
Incorrect |
217 ms |
17656 KB |
Output isn't correct |
48 |
Incorrect |
224 ms |
17656 KB |
Output isn't correct |
49 |
Incorrect |
195 ms |
16860 KB |
Output isn't correct |
50 |
Incorrect |
215 ms |
19396 KB |
Output isn't correct |
51 |
Incorrect |
210 ms |
19320 KB |
Output isn't correct |
52 |
Incorrect |
218 ms |
18976 KB |
Output isn't correct |
53 |
Execution timed out |
1069 ms |
70904 KB |
Time limit exceeded |
54 |
Incorrect |
224 ms |
17528 KB |
Output isn't correct |