답안 #120936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
120936 2019-06-25T19:15:09 Z thiago4532 Pipes (BOI13_pipes) C++17
35 / 100
276 ms 27004 KB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
const int maxm = 5e5 + 10;
vector<int> grafo[maxn];
int n;
int s[maxn];
map<pair<int, int>, int> mapa;
int val[maxn], ans[maxn];

namespace tree{

int nivel[maxn], pai[maxn], soma[maxn];
void dfs(int u, int p = 0) {
	pai[u] = p;

	for(auto v : grafo[u]) {
		if(v == p) continue;
		nivel[v] = nivel[u] + 1;
		dfs(v, u);
	}
}

};

int main() {
	int m;

	cin >> n >> m;
	if(m > n) {
		cout << "0\n";
		return 0;
	}
	int total = 0;
	for(int i=1;i<=n;i++)
		cin >> s[i], total += s[i];

	for(int i=1;i<=m;i++) {
		int a, b;
		cin >> a >> b;
		grafo[a].push_back(b);
		grafo[a].push_back(b);
		mapa[{a, b}] = i;
		mapa[{b, a}] = i;
	}
	if(n - 1 == m) {
		tree::dfs(1);
		vector<pii> arr;
		for(int i=1;i<=n;i++)
			arr.push_back({tree::nivel[i], i});
		sort(arr.begin(), arr.end(), greater<pii>());

		for(auto e : arr) {
			int v = e.second, u = tree::pai[v];

			tree::soma[u] += (s[v] - tree::soma[v]);
			ans[mapa[{u, v}]] = (s[v] - tree::soma[v]);
		}

		for(int i=1;i<=m;i++)
			cout << 2*ans[i] << "\n";

	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2688 KB Output isn't correct
2 Incorrect 4 ms 2688 KB Output isn't correct
3 Incorrect 5 ms 2916 KB Output isn't correct
4 Incorrect 266 ms 26504 KB Output isn't correct
5 Incorrect 4 ms 2688 KB Output isn't correct
6 Incorrect 4 ms 2688 KB Output isn't correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Incorrect 3 ms 2688 KB Output isn't correct
9 Incorrect 6 ms 2944 KB Output isn't correct
10 Incorrect 5 ms 2944 KB Output isn't correct
11 Incorrect 5 ms 2944 KB Output isn't correct
12 Incorrect 6 ms 2944 KB Output isn't correct
13 Incorrect 200 ms 21584 KB Output isn't correct
14 Incorrect 246 ms 25168 KB Output isn't correct
15 Incorrect 262 ms 26656 KB Output isn't correct
16 Incorrect 225 ms 23024 KB Output isn't correct
17 Incorrect 271 ms 26508 KB Output isn't correct
18 Incorrect 262 ms 27004 KB Output isn't correct
19 Incorrect 260 ms 26608 KB Output isn't correct
20 Incorrect 4 ms 2688 KB Output isn't correct
21 Incorrect 6 ms 2816 KB Output isn't correct
22 Incorrect 266 ms 26700 KB Output isn't correct
23 Incorrect 217 ms 21616 KB Output isn't correct
24 Incorrect 276 ms 26588 KB Output isn't correct
25 Incorrect 229 ms 22636 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2768 KB Output isn't correct
2 Incorrect 5 ms 2816 KB Output isn't correct
3 Incorrect 213 ms 18424 KB Output isn't correct
4 Correct 5 ms 2816 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Incorrect 4 ms 2688 KB Output isn't correct
9 Incorrect 4 ms 2688 KB Output isn't correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 3 ms 2688 KB Output is correct
12 Correct 4 ms 2816 KB Output is correct
13 Correct 4 ms 2688 KB Output is correct
14 Incorrect 5 ms 2688 KB Output isn't correct
15 Incorrect 5 ms 2816 KB Output isn't correct
16 Incorrect 5 ms 2816 KB Output isn't correct
17 Incorrect 5 ms 2816 KB Output isn't correct
18 Correct 4 ms 2688 KB Output is correct
19 Correct 4 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Incorrect 5 ms 2816 KB Output isn't correct
23 Incorrect 165 ms 16192 KB Output isn't correct
24 Incorrect 200 ms 19320 KB Output isn't correct
25 Incorrect 198 ms 18396 KB Output isn't correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 9 ms 2688 KB Output is correct
30 Incorrect 218 ms 18936 KB Output isn't correct
31 Incorrect 230 ms 19320 KB Output isn't correct
32 Incorrect 239 ms 19316 KB Output isn't correct
33 Incorrect 227 ms 19320 KB Output isn't correct
34 Correct 4 ms 2688 KB Output is correct
35 Correct 4 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 4 ms 2688 KB Output is correct
38 Incorrect 235 ms 19192 KB Output isn't correct
39 Incorrect 234 ms 19192 KB Output isn't correct
40 Incorrect 226 ms 19448 KB Output isn't correct
41 Incorrect 219 ms 19192 KB Output isn't correct
42 Correct 4 ms 2688 KB Output is correct
43 Correct 5 ms 2688 KB Output is correct
44 Correct 4 ms 2688 KB Output is correct
45 Correct 4 ms 2688 KB Output is correct
46 Incorrect 237 ms 19336 KB Output isn't correct
47 Incorrect 220 ms 19320 KB Output isn't correct
48 Incorrect 223 ms 19320 KB Output isn't correct
49 Incorrect 206 ms 18424 KB Output isn't correct
50 Correct 4 ms 2688 KB Output is correct
51 Correct 4 ms 2688 KB Output is correct
52 Correct 4 ms 2688 KB Output is correct
53 Correct 4 ms 2688 KB Output is correct
54 Incorrect 215 ms 19064 KB Output isn't correct