답안 #85889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
85889 2018-11-22T14:04:21 Z fasterthanyou Pipes (BOI13_pipes) C++14
74.0741 / 100
292 ms 17696 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
using namespace std;
 
int n, m, child[100015], tmp[100015];
long long d[100015], res[500015];
vector<pair<int, int> > g[100015];
pair<int, int> p[100015];
queue<int> q;
 
void dfs (int u, int pv)
{
	child[u] = 0;
	for (int i = 0; i < (int)g[u].size(); ++i)
	{
		int v = g[u][i].first;
		if (v == pv) continue;
 
		dfs(v, u);
		child[u] += child[v] + 1;
		p[v] = {u, g[u][i].second};
	}
}
 
void caseTree()
{
	p[1] = {-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].first] -= d[u];
		child[p[u].first] -= (tmp[u] + 1);
 
		if (p[u].first != -1) res[p[u].second] = d[u];
		if (child[p[u].first] < 1 && p[u].first != -1) q.push(p[u].first);
	}
	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, i + 1}),
		g[v].push_back({u, i + 1});
 
	if (m == n - 1) 
		caseTree();
	else cout << 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Correct 4 ms 2812 KB Output is correct
3 Correct 4 ms 2984 KB Output is correct
4 Correct 75 ms 10208 KB Output is correct
5 Correct 4 ms 10208 KB Output is correct
6 Correct 4 ms 10208 KB Output is correct
7 Correct 4 ms 10208 KB Output is correct
8 Correct 4 ms 10208 KB Output is correct
9 Correct 4 ms 10208 KB Output is correct
10 Correct 6 ms 10208 KB Output is correct
11 Correct 5 ms 10208 KB Output is correct
12 Correct 6 ms 10208 KB Output is correct
13 Correct 61 ms 10208 KB Output is correct
14 Correct 79 ms 10208 KB Output is correct
15 Correct 72 ms 10444 KB Output is correct
16 Correct 62 ms 10444 KB Output is correct
17 Correct 89 ms 10508 KB Output is correct
18 Correct 81 ms 10508 KB Output is correct
19 Correct 78 ms 13596 KB Output is correct
20 Correct 4 ms 13596 KB Output is correct
21 Correct 6 ms 13596 KB Output is correct
22 Correct 92 ms 13596 KB Output is correct
23 Correct 57 ms 13596 KB Output is correct
24 Correct 78 ms 13596 KB Output is correct
25 Correct 63 ms 13596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 13596 KB Output isn't correct
2 Incorrect 4 ms 13596 KB Output isn't correct
3 Correct 49 ms 13596 KB Output is correct
4 Correct 62 ms 13596 KB Output is correct
5 Correct 62 ms 13596 KB Output is correct
6 Correct 283 ms 17696 KB Output is correct
7 Incorrect 4 ms 17696 KB Output isn't correct
8 Incorrect 5 ms 17696 KB Output isn't correct
9 Correct 6 ms 17696 KB Output is correct
10 Correct 4 ms 17696 KB Output is correct
11 Correct 4 ms 17696 KB Output is correct
12 Correct 4 ms 17696 KB Output is correct
13 Correct 4 ms 17696 KB Output is correct
14 Incorrect 4 ms 17696 KB Output isn't correct
15 Incorrect 5 ms 17696 KB Output isn't correct
16 Incorrect 4 ms 17696 KB Output isn't correct
17 Correct 4 ms 17696 KB Output is correct
18 Correct 6 ms 17696 KB Output is correct
19 Correct 4 ms 17696 KB Output is correct
20 Correct 4 ms 17696 KB Output is correct
21 Correct 5 ms 17696 KB Output is correct
22 Incorrect 4 ms 17696 KB Output isn't correct
23 Incorrect 42 ms 17696 KB Output isn't correct
24 Incorrect 55 ms 17696 KB Output isn't correct
25 Correct 102 ms 17696 KB Output is correct
26 Correct 102 ms 17696 KB Output is correct
27 Correct 59 ms 17696 KB Output is correct
28 Correct 58 ms 17696 KB Output is correct
29 Correct 187 ms 17696 KB Output is correct
30 Incorrect 59 ms 17696 KB Output isn't correct
31 Incorrect 92 ms 17696 KB Output isn't correct
32 Incorrect 69 ms 17696 KB Output isn't correct
33 Correct 61 ms 17696 KB Output is correct
34 Correct 53 ms 17696 KB Output is correct
35 Correct 56 ms 17696 KB Output is correct
36 Correct 54 ms 17696 KB Output is correct
37 Correct 292 ms 17696 KB Output is correct
38 Incorrect 61 ms 17696 KB Output isn't correct
39 Incorrect 57 ms 17696 KB Output isn't correct
40 Incorrect 59 ms 17696 KB Output isn't correct
41 Correct 55 ms 17696 KB Output is correct
42 Correct 59 ms 17696 KB Output is correct
43 Correct 53 ms 17696 KB Output is correct
44 Correct 51 ms 17696 KB Output is correct
45 Correct 176 ms 17696 KB Output is correct
46 Incorrect 53 ms 17696 KB Output isn't correct
47 Incorrect 64 ms 17696 KB Output isn't correct
48 Incorrect 50 ms 17696 KB Output isn't correct
49 Correct 54 ms 17696 KB Output is correct
50 Correct 53 ms 17696 KB Output is correct
51 Correct 54 ms 17696 KB Output is correct
52 Correct 74 ms 17696 KB Output is correct
53 Correct 192 ms 17696 KB Output is correct
54 Incorrect 52 ms 17696 KB Output isn't correct