Submission #85882

# Submission time Handle Problem Language Result Execution time Memory
85882 2018-11-22T12:50:55 Z fasterthanyou Pipes (BOI13_pipes) C++11
28.5185 / 100
1000 ms 85872 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] < 1)
			{
				d[p[u]] -= d[u];
				--child[p[u]];
				res[mp[{u, p[u]}]] = d[u];
			}
	}

	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 Incorrect 5 ms 2780 KB Output isn't correct
2 Incorrect 5 ms 2820 KB Output isn't correct
3 Incorrect 176 ms 3080 KB Output isn't correct
4 Execution timed out 1076 ms 22532 KB Time limit exceeded
5 Incorrect 4 ms 22532 KB Output isn't correct
6 Incorrect 5 ms 22532 KB Output isn't correct
7 Incorrect 4 ms 22532 KB Output isn't correct
8 Incorrect 4 ms 22532 KB Output isn't correct
9 Incorrect 39 ms 22532 KB Output isn't correct
10 Incorrect 186 ms 22532 KB Output isn't correct
11 Incorrect 201 ms 22532 KB Output isn't correct
12 Incorrect 507 ms 22532 KB Output isn't correct
13 Execution timed out 1078 ms 22532 KB Time limit exceeded
14 Execution timed out 1079 ms 24584 KB Time limit exceeded
15 Execution timed out 1030 ms 26084 KB Time limit exceeded
16 Execution timed out 1082 ms 26084 KB Time limit exceeded
17 Execution timed out 1074 ms 26084 KB Time limit exceeded
18 Execution timed out 1068 ms 26176 KB Time limit exceeded
19 Execution timed out 1070 ms 29152 KB Time limit exceeded
20 Incorrect 5 ms 29152 KB Output isn't correct
21 Incorrect 62 ms 29152 KB Output isn't correct
22 Execution timed out 1070 ms 29152 KB Time limit exceeded
23 Execution timed out 1082 ms 29152 KB Time limit exceeded
24 Execution timed out 1080 ms 29152 KB Time limit exceeded
25 Execution timed out 1085 ms 29152 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 29152 KB Output isn't correct
2 Incorrect 4 ms 29152 KB Output isn't correct
3 Incorrect 159 ms 29152 KB Output isn't correct
4 Correct 195 ms 30852 KB Output is correct
5 Correct 198 ms 31964 KB Output is correct
6 Execution timed out 1082 ms 78804 KB Time limit exceeded
7 Incorrect 4 ms 78804 KB Output isn't correct
8 Incorrect 4 ms 78804 KB Output isn't correct
9 Incorrect 4 ms 78804 KB Output isn't correct
10 Correct 6 ms 78804 KB Output is correct
11 Correct 5 ms 78804 KB Output is correct
12 Correct 4 ms 78804 KB Output is correct
13 Correct 4 ms 78804 KB Output is correct
14 Incorrect 4 ms 78804 KB Output isn't correct
15 Incorrect 5 ms 78804 KB Output isn't correct
16 Incorrect 5 ms 78804 KB Output isn't correct
17 Incorrect 5 ms 78804 KB Output isn't correct
18 Correct 6 ms 78804 KB Output is correct
19 Correct 5 ms 78804 KB Output is correct
20 Correct 5 ms 78804 KB Output is correct
21 Correct 7 ms 78804 KB Output is correct
22 Incorrect 5 ms 78804 KB Output isn't correct
23 Incorrect 170 ms 78804 KB Output isn't correct
24 Incorrect 195 ms 78804 KB Output isn't correct
25 Incorrect 184 ms 78804 KB Output isn't correct
26 Correct 224 ms 78804 KB Output is correct
27 Correct 189 ms 78804 KB Output is correct
28 Correct 230 ms 78804 KB Output is correct
29 Execution timed out 1039 ms 78804 KB Time limit exceeded
30 Incorrect 205 ms 78804 KB Output isn't correct
31 Incorrect 210 ms 78804 KB Output isn't correct
32 Incorrect 212 ms 78804 KB Output isn't correct
33 Incorrect 224 ms 78804 KB Output isn't correct
34 Correct 205 ms 78804 KB Output is correct
35 Correct 211 ms 78804 KB Output is correct
36 Correct 221 ms 78804 KB Output is correct
37 Execution timed out 1073 ms 85872 KB Time limit exceeded
38 Incorrect 243 ms 85872 KB Output isn't correct
39 Incorrect 213 ms 85872 KB Output isn't correct
40 Incorrect 226 ms 85872 KB Output isn't correct
41 Incorrect 214 ms 85872 KB Output isn't correct
42 Correct 229 ms 85872 KB Output is correct
43 Correct 218 ms 85872 KB Output is correct
44 Correct 213 ms 85872 KB Output is correct
45 Execution timed out 1071 ms 85872 KB Time limit exceeded
46 Incorrect 239 ms 85872 KB Output isn't correct
47 Incorrect 210 ms 85872 KB Output isn't correct
48 Incorrect 195 ms 85872 KB Output isn't correct
49 Incorrect 182 ms 85872 KB Output isn't correct
50 Correct 194 ms 85872 KB Output is correct
51 Correct 208 ms 85872 KB Output is correct
52 Correct 201 ms 85872 KB Output is correct
53 Execution timed out 1075 ms 85872 KB Time limit exceeded
54 Incorrect 202 ms 85872 KB Output isn't correct