#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
using namespace std;
int n, m, child[100015], p[100015], tmp[100015];
bool vst[100015];
long long d[100015], res[500015];
vector<int> g[100015];
queue<int> q;
map<pair<int, int>, int> mp;
void dfs (int u, int pv)
{
vst[u] = 1;
child[u] = 0;
for (int i = 0; i < (int)g[u].size(); ++i)
{
int v = g[u][i];
if (v == pv) continue;
dfs(v, u);
child[u] += child[v] + 1;
p[v] = u;
}
}
void caseTree()
{
p[1] = -1;
dfs(1, -1);
for (int i = 2; i <= n; ++i)
if (child[i] == 0) q.push(i);
for (int i = 1; i <= n; ++i)
tmp[i] = child[i];
while (!q.empty())
{
int u = q.front(); q.pop();
d[p[u]] -= d[u];
child[p[u]] -= (tmp[u] + 1);
if (p[u] != -1) res[mp[{u, p[u]}]] = d[u];
if (child[p[u]] < 1 && p[u] != -1) q.push(p[u]);
}
for (int id = 1; id <= m; ++id)
cout << res[id] << '\n';
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
//freopen("pipes.inp", "r", stdin);
//freopen("pipes.out", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> d[i],
d[i] *= 2;
for (int i = 0, u, v; i < m; ++i)
cin >> u >> v,
g[u].push_back(v),
g[v].push_back(u),
mp[{u, v}] = i + 1,
mp[{v, u}] = i + 1;
if (m == n - 1)
caseTree();
else cout << 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2684 KB |
Output is correct |
2 |
Correct |
4 ms |
2932 KB |
Output is correct |
3 |
Correct |
6 ms |
3220 KB |
Output is correct |
4 |
Correct |
294 ms |
21944 KB |
Output is correct |
5 |
Correct |
4 ms |
21944 KB |
Output is correct |
6 |
Correct |
4 ms |
21944 KB |
Output is correct |
7 |
Correct |
5 ms |
21944 KB |
Output is correct |
8 |
Correct |
4 ms |
21944 KB |
Output is correct |
9 |
Correct |
5 ms |
21944 KB |
Output is correct |
10 |
Correct |
5 ms |
21944 KB |
Output is correct |
11 |
Correct |
6 ms |
21944 KB |
Output is correct |
12 |
Correct |
5 ms |
21944 KB |
Output is correct |
13 |
Correct |
235 ms |
21944 KB |
Output is correct |
14 |
Correct |
295 ms |
21944 KB |
Output is correct |
15 |
Correct |
302 ms |
22156 KB |
Output is correct |
16 |
Correct |
279 ms |
22156 KB |
Output is correct |
17 |
Correct |
299 ms |
22156 KB |
Output is correct |
18 |
Correct |
311 ms |
22372 KB |
Output is correct |
19 |
Correct |
352 ms |
25148 KB |
Output is correct |
20 |
Correct |
4 ms |
25148 KB |
Output is correct |
21 |
Correct |
7 ms |
25148 KB |
Output is correct |
22 |
Correct |
319 ms |
25148 KB |
Output is correct |
23 |
Correct |
235 ms |
25148 KB |
Output is correct |
24 |
Correct |
283 ms |
25148 KB |
Output is correct |
25 |
Correct |
215 ms |
25148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
25148 KB |
Output isn't correct |
2 |
Incorrect |
6 ms |
25148 KB |
Output isn't correct |
3 |
Correct |
173 ms |
25148 KB |
Output is correct |
4 |
Correct |
201 ms |
25148 KB |
Output is correct |
5 |
Correct |
195 ms |
25148 KB |
Output is correct |
6 |
Execution timed out |
1081 ms |
74652 KB |
Time limit exceeded |
7 |
Incorrect |
4 ms |
74652 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
74652 KB |
Output isn't correct |
9 |
Correct |
4 ms |
74652 KB |
Output is correct |
10 |
Correct |
4 ms |
74652 KB |
Output is correct |
11 |
Correct |
4 ms |
74652 KB |
Output is correct |
12 |
Correct |
4 ms |
74652 KB |
Output is correct |
13 |
Correct |
4 ms |
74652 KB |
Output is correct |
14 |
Incorrect |
5 ms |
74652 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
74652 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
74652 KB |
Output isn't correct |
17 |
Correct |
5 ms |
74652 KB |
Output is correct |
18 |
Correct |
5 ms |
74652 KB |
Output is correct |
19 |
Correct |
5 ms |
74652 KB |
Output is correct |
20 |
Correct |
6 ms |
74652 KB |
Output is correct |
21 |
Correct |
6 ms |
74652 KB |
Output is correct |
22 |
Incorrect |
5 ms |
74652 KB |
Output isn't correct |
23 |
Incorrect |
174 ms |
74652 KB |
Output isn't correct |
24 |
Incorrect |
200 ms |
74652 KB |
Output isn't correct |
25 |
Correct |
182 ms |
74652 KB |
Output is correct |
26 |
Correct |
188 ms |
74652 KB |
Output is correct |
27 |
Correct |
181 ms |
74652 KB |
Output is correct |
28 |
Correct |
210 ms |
74652 KB |
Output is correct |
29 |
Correct |
939 ms |
74652 KB |
Output is correct |
30 |
Incorrect |
180 ms |
74652 KB |
Output isn't correct |
31 |
Incorrect |
195 ms |
74652 KB |
Output isn't correct |
32 |
Incorrect |
196 ms |
74652 KB |
Output isn't correct |
33 |
Correct |
224 ms |
74652 KB |
Output is correct |
34 |
Correct |
192 ms |
74652 KB |
Output is correct |
35 |
Correct |
207 ms |
74652 KB |
Output is correct |
36 |
Correct |
206 ms |
74652 KB |
Output is correct |
37 |
Execution timed out |
1069 ms |
74652 KB |
Time limit exceeded |
38 |
Incorrect |
207 ms |
74652 KB |
Output isn't correct |
39 |
Incorrect |
215 ms |
74652 KB |
Output isn't correct |
40 |
Incorrect |
176 ms |
74652 KB |
Output isn't correct |
41 |
Correct |
221 ms |
74652 KB |
Output is correct |
42 |
Correct |
211 ms |
74652 KB |
Output is correct |
43 |
Correct |
184 ms |
74652 KB |
Output is correct |
44 |
Correct |
198 ms |
74652 KB |
Output is correct |
45 |
Execution timed out |
1018 ms |
74652 KB |
Time limit exceeded |
46 |
Incorrect |
167 ms |
74652 KB |
Output isn't correct |
47 |
Incorrect |
154 ms |
74652 KB |
Output isn't correct |
48 |
Incorrect |
163 ms |
74652 KB |
Output isn't correct |
49 |
Correct |
141 ms |
74652 KB |
Output is correct |
50 |
Correct |
164 ms |
74652 KB |
Output is correct |
51 |
Correct |
192 ms |
74652 KB |
Output is correct |
52 |
Correct |
175 ms |
74652 KB |
Output is correct |
53 |
Execution timed out |
1051 ms |
74652 KB |
Time limit exceeded |
54 |
Incorrect |
217 ms |
74652 KB |
Output isn't correct |