#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
using namespace std;
int n, m;
vector<int> child, p, tmp;
vector<bool> vst;
vector<long long> d, res;
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;
d.resize(n + 1);
child.resize(n + 1, 0);
tmp.resize(n + 1);
p.resize(n + 1);
res.resize(m + 1);
vst.resize(n + 1, 0);
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 |
Runtime error |
10 ms |
5496 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
9 ms |
5568 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
11 ms |
5816 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Correct |
256 ms |
24764 KB |
Output is correct |
5 |
Runtime error |
10 ms |
24764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
10 ms |
24764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
9 ms |
24764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
10 ms |
24764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
11 ms |
24764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
11 ms |
24764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Runtime error |
11 ms |
24764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Runtime error |
11 ms |
24764 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Correct |
184 ms |
24764 KB |
Output is correct |
14 |
Correct |
236 ms |
24764 KB |
Output is correct |
15 |
Correct |
248 ms |
25204 KB |
Output is correct |
16 |
Correct |
209 ms |
25204 KB |
Output is correct |
17 |
Correct |
292 ms |
25204 KB |
Output is correct |
18 |
Correct |
269 ms |
25424 KB |
Output is correct |
19 |
Correct |
309 ms |
28040 KB |
Output is correct |
20 |
Runtime error |
10 ms |
28040 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
21 |
Runtime error |
11 ms |
28040 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
22 |
Correct |
285 ms |
28040 KB |
Output is correct |
23 |
Correct |
239 ms |
28040 KB |
Output is correct |
24 |
Correct |
286 ms |
28040 KB |
Output is correct |
25 |
Correct |
243 ms |
28040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
28040 KB |
Output isn't correct |
2 |
Incorrect |
6 ms |
28040 KB |
Output isn't correct |
3 |
Correct |
160 ms |
28040 KB |
Output is correct |
4 |
Correct |
181 ms |
28040 KB |
Output is correct |
5 |
Correct |
174 ms |
28040 KB |
Output is correct |
6 |
Execution timed out |
1067 ms |
79844 KB |
Time limit exceeded |
7 |
Incorrect |
4 ms |
79844 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
79844 KB |
Output isn't correct |
9 |
Correct |
4 ms |
79844 KB |
Output is correct |
10 |
Correct |
4 ms |
79844 KB |
Output is correct |
11 |
Correct |
4 ms |
79844 KB |
Output is correct |
12 |
Correct |
4 ms |
79844 KB |
Output is correct |
13 |
Correct |
4 ms |
79844 KB |
Output is correct |
14 |
Incorrect |
4 ms |
79844 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
79844 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
79844 KB |
Output isn't correct |
17 |
Correct |
5 ms |
79844 KB |
Output is correct |
18 |
Correct |
5 ms |
79844 KB |
Output is correct |
19 |
Correct |
5 ms |
79844 KB |
Output is correct |
20 |
Correct |
5 ms |
79844 KB |
Output is correct |
21 |
Correct |
6 ms |
79844 KB |
Output is correct |
22 |
Incorrect |
5 ms |
79844 KB |
Output isn't correct |
23 |
Incorrect |
125 ms |
79844 KB |
Output isn't correct |
24 |
Incorrect |
184 ms |
79844 KB |
Output isn't correct |
25 |
Correct |
156 ms |
79844 KB |
Output is correct |
26 |
Correct |
166 ms |
79844 KB |
Output is correct |
27 |
Correct |
215 ms |
79844 KB |
Output is correct |
28 |
Correct |
186 ms |
79844 KB |
Output is correct |
29 |
Correct |
898 ms |
79844 KB |
Output is correct |
30 |
Incorrect |
158 ms |
79844 KB |
Output isn't correct |
31 |
Incorrect |
162 ms |
79844 KB |
Output isn't correct |
32 |
Incorrect |
189 ms |
79844 KB |
Output isn't correct |
33 |
Correct |
166 ms |
79844 KB |
Output is correct |
34 |
Correct |
146 ms |
79844 KB |
Output is correct |
35 |
Correct |
151 ms |
79844 KB |
Output is correct |
36 |
Correct |
166 ms |
79844 KB |
Output is correct |
37 |
Execution timed out |
1055 ms |
83972 KB |
Time limit exceeded |
38 |
Incorrect |
152 ms |
83972 KB |
Output isn't correct |
39 |
Incorrect |
153 ms |
83972 KB |
Output isn't correct |
40 |
Incorrect |
182 ms |
83972 KB |
Output isn't correct |
41 |
Correct |
189 ms |
83972 KB |
Output is correct |
42 |
Correct |
169 ms |
83972 KB |
Output is correct |
43 |
Correct |
186 ms |
83972 KB |
Output is correct |
44 |
Correct |
154 ms |
83972 KB |
Output is correct |
45 |
Correct |
839 ms |
83972 KB |
Output is correct |
46 |
Incorrect |
187 ms |
83972 KB |
Output isn't correct |
47 |
Incorrect |
160 ms |
83972 KB |
Output isn't correct |
48 |
Incorrect |
188 ms |
83972 KB |
Output isn't correct |
49 |
Correct |
165 ms |
83972 KB |
Output is correct |
50 |
Correct |
194 ms |
83972 KB |
Output is correct |
51 |
Correct |
163 ms |
83972 KB |
Output is correct |
52 |
Correct |
164 ms |
83972 KB |
Output is correct |
53 |
Execution timed out |
1044 ms |
83972 KB |
Time limit exceeded |
54 |
Incorrect |
201 ms |
83972 KB |
Output isn't correct |