Submission #85883

# Submission time Handle Problem Language Result Execution time Memory
85883 2018-11-22T12:54:09 Z fasterthanyou Pipes (BOI13_pipes) C++14
29.8148 / 100
1000 ms 87316 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;

int n, m, child[100015], p[100015];
bool vst[100015];
long long d[100015], res[500015];
vector<int> g[100015];
map<pair<int, int>, int> mp;

void dfs (int u)
{
	vst[u] = 1;
	child[u] = 0;
	for (int i = 0; i < (int)g[u].size(); ++i)
	{
		int v = g[u][i];
		if (!vst[v])
		{
			dfs(v);
			child[u] += 1 + child[v];
			p[v] = u;
		}
	}
}

void caseTree()
{
	dfs(1);
	while (child[1] > 0)
	{
		for (int u = 1; u <= n; ++u)
			if (child[u] == 0)
			{
				d[p[u]] -= d[u];
				--child[p[u]];
				res[mp[{u, p[u]}]] = d[u];
				child[u] = -1;
			}
	}

	if (d[1] != 0) cout << 0;
	else
	{
		for (int id = 0; id < m; ++id)
			cout << res[id] << '\n';
	}
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	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,
		mp[{v, u}] = i;

	if (m == n - 1) 
		caseTree();
	else if (n < m)
		cout << 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 2680 KB Time limit exceeded
2 Execution timed out 1075 ms 2812 KB Time limit exceeded
3 Execution timed out 1070 ms 2976 KB Time limit exceeded
4 Execution timed out 1071 ms 21052 KB Time limit exceeded
5 Execution timed out 1081 ms 21052 KB Time limit exceeded
6 Execution timed out 1086 ms 21052 KB Time limit exceeded
7 Execution timed out 1081 ms 21052 KB Time limit exceeded
8 Execution timed out 1078 ms 21052 KB Time limit exceeded
9 Execution timed out 1083 ms 21052 KB Time limit exceeded
10 Execution timed out 1080 ms 21052 KB Time limit exceeded
11 Execution timed out 1076 ms 21052 KB Time limit exceeded
12 Execution timed out 1087 ms 21052 KB Time limit exceeded
13 Execution timed out 1082 ms 21052 KB Time limit exceeded
14 Execution timed out 1090 ms 21052 KB Time limit exceeded
15 Execution timed out 1085 ms 22140 KB Time limit exceeded
16 Execution timed out 1081 ms 22140 KB Time limit exceeded
17 Execution timed out 1085 ms 24992 KB Time limit exceeded
18 Execution timed out 1083 ms 26540 KB Time limit exceeded
19 Execution timed out 1086 ms 31180 KB Time limit exceeded
20 Execution timed out 1091 ms 31180 KB Time limit exceeded
21 Execution timed out 1078 ms 31180 KB Time limit exceeded
22 Execution timed out 1089 ms 31180 KB Time limit exceeded
23 Execution timed out 1079 ms 31180 KB Time limit exceeded
24 Execution timed out 1073 ms 31180 KB Time limit exceeded
25 Execution timed out 1076 ms 31180 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 31180 KB Output isn't correct
2 Incorrect 4 ms 31180 KB Output isn't correct
3 Incorrect 176 ms 31180 KB Output isn't correct
4 Correct 201 ms 31180 KB Output is correct
5 Correct 190 ms 31180 KB Output is correct
6 Execution timed out 1089 ms 87316 KB Time limit exceeded
7 Incorrect 4 ms 87316 KB Output isn't correct
8 Incorrect 4 ms 87316 KB Output isn't correct
9 Incorrect 4 ms 87316 KB Output isn't correct
10 Correct 4 ms 87316 KB Output is correct
11 Correct 4 ms 87316 KB Output is correct
12 Correct 4 ms 87316 KB Output is correct
13 Correct 4 ms 87316 KB Output is correct
14 Incorrect 4 ms 87316 KB Output isn't correct
15 Incorrect 5 ms 87316 KB Output isn't correct
16 Incorrect 5 ms 87316 KB Output isn't correct
17 Incorrect 4 ms 87316 KB Output isn't correct
18 Correct 5 ms 87316 KB Output is correct
19 Correct 5 ms 87316 KB Output is correct
20 Correct 5 ms 87316 KB Output is correct
21 Correct 7 ms 87316 KB Output is correct
22 Incorrect 5 ms 87316 KB Output isn't correct
23 Incorrect 134 ms 87316 KB Output isn't correct
24 Incorrect 182 ms 87316 KB Output isn't correct
25 Incorrect 188 ms 87316 KB Output isn't correct
26 Correct 188 ms 87316 KB Output is correct
27 Correct 186 ms 87316 KB Output is correct
28 Correct 198 ms 87316 KB Output is correct
29 Correct 953 ms 87316 KB Output is correct
30 Incorrect 173 ms 87316 KB Output isn't correct
31 Incorrect 184 ms 87316 KB Output isn't correct
32 Incorrect 225 ms 87316 KB Output isn't correct
33 Incorrect 187 ms 87316 KB Output isn't correct
34 Correct 194 ms 87316 KB Output is correct
35 Correct 198 ms 87316 KB Output is correct
36 Correct 201 ms 87316 KB Output is correct
37 Execution timed out 1069 ms 87316 KB Time limit exceeded
38 Incorrect 255 ms 87316 KB Output isn't correct
39 Incorrect 217 ms 87316 KB Output isn't correct
40 Incorrect 181 ms 87316 KB Output isn't correct
41 Incorrect 203 ms 87316 KB Output isn't correct
42 Correct 176 ms 87316 KB Output is correct
43 Correct 172 ms 87316 KB Output is correct
44 Correct 192 ms 87316 KB Output is correct
45 Execution timed out 1016 ms 87316 KB Time limit exceeded
46 Incorrect 208 ms 87316 KB Output isn't correct
47 Incorrect 201 ms 87316 KB Output isn't correct
48 Incorrect 200 ms 87316 KB Output isn't correct
49 Incorrect 179 ms 87316 KB Output isn't correct
50 Correct 217 ms 87316 KB Output is correct
51 Correct 206 ms 87316 KB Output is correct
52 Correct 165 ms 87316 KB Output is correct
53 Execution timed out 1018 ms 87316 KB Time limit exceeded
54 Incorrect 203 ms 87316 KB Output isn't correct