답안 #125137

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125137 2019-07-04T17:31:32 Z thiago4532 Pipes (BOI13_pipes) C++17
74.0741 / 100
408 ms 23740 KB
#include <bits/stdc++.h>
#define int int64_t

using namespace std;
const int maxn = 1e5 + 10;
bool mark[maxn];
int ans[5*maxn], s[maxn], grau[maxn];
map<pair<int, int>, int> mapa;
int n;
vector<int> grafo[maxn];

int32_t 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], s[i] *= 2, total += s[i];

	for(int i=1;i<=m;i++) {
		int a, b;
		cin >> a >> b;
		grafo[a].push_back(b);
		grafo[b].push_back(a);
		mapa[{a, b}] = i;
		mapa[{b, a}] = i;

		grau[a]++;
		grau[b]++;
	}
	
	queue<int> fila;
	for(int i=1;i<=n;i++) {
		if(grau[i] == 1)
			fila.push(i);
	}

	while(!fila.empty()) {
		int u = fila.front();
		fila.pop();
		
		if(mark[u]) continue;
		mark[u] = true;

		// cout << u << ": " << s[u] << "\n";
		for(auto v : grafo[u]) {
			if(mark[v]) continue;
			grau[v]--;

			ans[mapa[{u, v}]] = s[u], s[v] -= s[u];
			if(grau[v] == 1) fila.push(v);
		}
	}
 	for(int i=1;i<=m;i++)
 		cout << ans[i] << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2808 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 6 ms 2936 KB Output is correct
4 Correct 401 ms 23540 KB Output is correct
5 Correct 5 ms 2680 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 4 ms 2680 KB Output is correct
9 Correct 6 ms 2936 KB Output is correct
10 Correct 6 ms 2936 KB Output is correct
11 Correct 6 ms 2812 KB Output is correct
12 Correct 6 ms 2808 KB Output is correct
13 Correct 305 ms 19536 KB Output is correct
14 Correct 362 ms 22620 KB Output is correct
15 Correct 400 ms 23740 KB Output is correct
16 Correct 326 ms 20564 KB Output is correct
17 Correct 391 ms 23488 KB Output is correct
18 Correct 384 ms 23608 KB Output is correct
19 Correct 408 ms 22904 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 6 ms 2936 KB Output is correct
22 Correct 394 ms 23648 KB Output is correct
23 Correct 299 ms 19448 KB Output is correct
24 Correct 387 ms 23684 KB Output is correct
25 Correct 310 ms 20216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2680 KB Output isn't correct
2 Incorrect 4 ms 2680 KB Output isn't correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2652 KB Output is correct
5 Correct 4 ms 2652 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
7 Incorrect 4 ms 2680 KB Output isn't correct
8 Incorrect 4 ms 2680 KB Output isn't correct
9 Correct 4 ms 2680 KB Output is correct
10 Correct 4 ms 2684 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 4 ms 2680 KB Output is correct
13 Correct 4 ms 2680 KB Output is correct
14 Incorrect 4 ms 2680 KB Output isn't correct
15 Incorrect 4 ms 2680 KB Output isn't correct
16 Incorrect 4 ms 2680 KB Output isn't correct
17 Correct 4 ms 2680 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 4 ms 2652 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Incorrect 4 ms 2680 KB Output isn't correct
23 Incorrect 4 ms 2680 KB Output isn't correct
24 Incorrect 4 ms 2680 KB Output isn't correct
25 Correct 4 ms 2680 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2552 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Incorrect 4 ms 2680 KB Output isn't correct
31 Incorrect 4 ms 2680 KB Output isn't correct
32 Incorrect 4 ms 2680 KB Output isn't correct
33 Correct 4 ms 2680 KB Output is correct
34 Correct 4 ms 2684 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 4 ms 2680 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Incorrect 4 ms 2680 KB Output isn't correct
39 Incorrect 4 ms 2680 KB Output isn't correct
40 Incorrect 4 ms 2680 KB Output isn't correct
41 Correct 4 ms 2680 KB Output is correct
42 Correct 4 ms 2680 KB Output is correct
43 Correct 4 ms 2680 KB Output is correct
44 Correct 4 ms 2680 KB Output is correct
45 Correct 4 ms 2680 KB Output is correct
46 Incorrect 4 ms 2680 KB Output isn't correct
47 Incorrect 4 ms 2680 KB Output isn't correct
48 Incorrect 4 ms 2680 KB Output isn't correct
49 Correct 4 ms 2680 KB Output is correct
50 Correct 5 ms 2680 KB Output is correct
51 Correct 6 ms 2680 KB Output is correct
52 Correct 6 ms 2680 KB Output is correct
53 Correct 4 ms 2680 KB Output is correct
54 Incorrect 4 ms 2808 KB Output isn't correct