Submission #85881

# Submission time Handle Problem Language Result Execution time Memory
85881 2018-11-22T12:50:55 Z fasterthanyou Pipes (BOI13_pipes) C++11
29.8148 / 100
1000 ms 132096 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 2680 KB Output isn't correct
2 Incorrect 4 ms 2804 KB Output isn't correct
3 Incorrect 172 ms 2980 KB Output isn't correct
4 Execution timed out 1060 ms 20848 KB Time limit exceeded
5 Incorrect 4 ms 20848 KB Output isn't correct
6 Incorrect 6 ms 20848 KB Output isn't correct
7 Incorrect 5 ms 20848 KB Output isn't correct
8 Incorrect 5 ms 20848 KB Output isn't correct
9 Incorrect 35 ms 20848 KB Output isn't correct
10 Incorrect 178 ms 20848 KB Output isn't correct
11 Incorrect 188 ms 20848 KB Output isn't correct
12 Incorrect 547 ms 20848 KB Output isn't correct
13 Execution timed out 1082 ms 20848 KB Time limit exceeded
14 Execution timed out 1080 ms 20848 KB Time limit exceeded
15 Execution timed out 1004 ms 22144 KB Time limit exceeded
16 Execution timed out 1073 ms 22144 KB Time limit exceeded
17 Execution timed out 1078 ms 25012 KB Time limit exceeded
18 Execution timed out 1080 ms 26556 KB Time limit exceeded
19 Execution timed out 1076 ms 31232 KB Time limit exceeded
20 Incorrect 5 ms 31232 KB Output isn't correct
21 Incorrect 61 ms 31232 KB Output isn't correct
22 Execution timed out 1077 ms 31232 KB Time limit exceeded
23 Execution timed out 1084 ms 31232 KB Time limit exceeded
24 Execution timed out 1069 ms 31232 KB Time limit exceeded
25 Execution timed out 1076 ms 31232 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 31232 KB Output isn't correct
2 Incorrect 4 ms 31232 KB Output isn't correct
3 Incorrect 160 ms 31232 KB Output isn't correct
4 Correct 187 ms 31232 KB Output is correct
5 Correct 195 ms 31232 KB Output is correct
6 Execution timed out 1075 ms 82600 KB Time limit exceeded
7 Incorrect 4 ms 82600 KB Output isn't correct
8 Incorrect 4 ms 82600 KB Output isn't correct
9 Incorrect 5 ms 82600 KB Output isn't correct
10 Correct 4 ms 82600 KB Output is correct
11 Correct 4 ms 82600 KB Output is correct
12 Correct 5 ms 82600 KB Output is correct
13 Correct 4 ms 82600 KB Output is correct
14 Incorrect 4 ms 82600 KB Output isn't correct
15 Incorrect 4 ms 82600 KB Output isn't correct
16 Incorrect 5 ms 82600 KB Output isn't correct
17 Incorrect 5 ms 82600 KB Output isn't correct
18 Correct 5 ms 82600 KB Output is correct
19 Correct 6 ms 82600 KB Output is correct
20 Correct 5 ms 82600 KB Output is correct
21 Correct 6 ms 82600 KB Output is correct
22 Incorrect 5 ms 82600 KB Output isn't correct
23 Incorrect 157 ms 82600 KB Output isn't correct
24 Incorrect 196 ms 82600 KB Output isn't correct
25 Incorrect 180 ms 82600 KB Output isn't correct
26 Correct 213 ms 82600 KB Output is correct
27 Correct 219 ms 82600 KB Output is correct
28 Correct 206 ms 82600 KB Output is correct
29 Correct 998 ms 88288 KB Output is correct
30 Incorrect 211 ms 88288 KB Output isn't correct
31 Incorrect 226 ms 88288 KB Output isn't correct
32 Incorrect 206 ms 88288 KB Output isn't correct
33 Incorrect 207 ms 88288 KB Output isn't correct
34 Correct 221 ms 88288 KB Output is correct
35 Correct 201 ms 88288 KB Output is correct
36 Correct 212 ms 88288 KB Output is correct
37 Execution timed out 1032 ms 108848 KB Time limit exceeded
38 Incorrect 220 ms 108848 KB Output isn't correct
39 Incorrect 235 ms 108848 KB Output isn't correct
40 Incorrect 219 ms 108848 KB Output isn't correct
41 Incorrect 223 ms 108848 KB Output isn't correct
42 Correct 209 ms 108848 KB Output is correct
43 Correct 206 ms 108848 KB Output is correct
44 Correct 203 ms 108848 KB Output is correct
45 Execution timed out 1084 ms 126736 KB Time limit exceeded
46 Incorrect 199 ms 126736 KB Output isn't correct
47 Incorrect 205 ms 126736 KB Output isn't correct
48 Incorrect 195 ms 126736 KB Output isn't correct
49 Incorrect 192 ms 126736 KB Output isn't correct
50 Correct 185 ms 126736 KB Output is correct
51 Correct 196 ms 126736 KB Output is correct
52 Correct 194 ms 126736 KB Output is correct
53 Execution timed out 1064 ms 132096 KB Time limit exceeded
54 Runtime error 209 ms 132096 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.