답안 #84247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
84247 2018-11-14T03:03:46 Z IOrtroiii Pipes (BOI13_pipes) C++14
74.0741 / 100
91 ms 9380 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 100005;

int n, m;
int deg[N];
bool ok[N];
long long a[N], ans[N];
vector<pair<int,int>> g[N];

void dfs(int u,int p) {
	
}

int main() {
	scanf("%d %d", &n, &m);
	if (n < m) return printf("0\n"),0;
	for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
	for (int i = 1; i <= m; ++i) {
		int u, v; scanf("%d %d", &u, &v);
		++deg[u], ++deg[v];
		g[u].push_back({v, i}), g[v].push_back({u, i});	
	}
	queue<int> q;
	for (int u = 1; u <= n; ++u) if (deg[u] == 1) {
		q.push(u);
	}
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (auto e : g[u]) {
			int v = e.first;
			int id = e.second;
			if (ok[v] == false) {
				ans[id] = a[u];
				a[u] -= ans[id];
				a[v] -= ans[id];
				ok[u] = true;
				if (--deg[v] == 1) {
					q.push(v);
				}
			}
		}
	}
  	for (int i = 1; i <= n; ++i) if (a[i]) return printf("0\n"),0;
	for (int i = 1; i <= m; ++i) if (ans[i] > (long long) 5e8 || ans[i] < (long long) -5e8) {
		return printf("0\n"),0;
	}
	for (int i = 1; i <= m; ++i) printf("%lld\n", 2 * ans[i]);
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:19:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
                               ~~~~~^~~~~~~~~~~~~~~
pipes.cpp:21:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int u, v; scanf("%d %d", &u, &v);
             ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2852 KB Output is correct
3 Correct 4 ms 2852 KB Output is correct
4 Correct 87 ms 9136 KB Output is correct
5 Correct 5 ms 9136 KB Output is correct
6 Correct 4 ms 9136 KB Output is correct
7 Correct 5 ms 9136 KB Output is correct
8 Correct 4 ms 9136 KB Output is correct
9 Correct 4 ms 9136 KB Output is correct
10 Correct 4 ms 9136 KB Output is correct
11 Correct 5 ms 9136 KB Output is correct
12 Correct 4 ms 9136 KB Output is correct
13 Correct 60 ms 9136 KB Output is correct
14 Correct 86 ms 9136 KB Output is correct
15 Correct 79 ms 9372 KB Output is correct
16 Correct 79 ms 9372 KB Output is correct
17 Correct 91 ms 9372 KB Output is correct
18 Correct 80 ms 9380 KB Output is correct
19 Correct 90 ms 9380 KB Output is correct
20 Correct 4 ms 9380 KB Output is correct
21 Correct 4 ms 9380 KB Output is correct
22 Correct 81 ms 9380 KB Output is correct
23 Correct 88 ms 9380 KB Output is correct
24 Correct 82 ms 9380 KB Output is correct
25 Correct 76 ms 9380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 9380 KB Output isn't correct
2 Incorrect 5 ms 9380 KB Output isn't correct
3 Correct 63 ms 9380 KB Output is correct
4 Correct 4 ms 9380 KB Output is correct
5 Correct 4 ms 9380 KB Output is correct
6 Correct 4 ms 9380 KB Output is correct
7 Incorrect 4 ms 9380 KB Output isn't correct
8 Incorrect 4 ms 9380 KB Output isn't correct
9 Correct 4 ms 9380 KB Output is correct
10 Correct 4 ms 9380 KB Output is correct
11 Correct 4 ms 9380 KB Output is correct
12 Correct 4 ms 9380 KB Output is correct
13 Correct 1 ms 9380 KB Output is correct
14 Incorrect 4 ms 9380 KB Output isn't correct
15 Incorrect 4 ms 9380 KB Output isn't correct
16 Incorrect 5 ms 9380 KB Output isn't correct
17 Correct 4 ms 9380 KB Output is correct
18 Correct 4 ms 9380 KB Output is correct
19 Correct 4 ms 9380 KB Output is correct
20 Correct 4 ms 9380 KB Output is correct
21 Correct 4 ms 9380 KB Output is correct
22 Incorrect 5 ms 9380 KB Output isn't correct
23 Incorrect 57 ms 9380 KB Output isn't correct
24 Incorrect 87 ms 9380 KB Output isn't correct
25 Correct 69 ms 9380 KB Output is correct
26 Correct 4 ms 9380 KB Output is correct
27 Correct 4 ms 9380 KB Output is correct
28 Correct 4 ms 9380 KB Output is correct
29 Correct 4 ms 9380 KB Output is correct
30 Incorrect 71 ms 9380 KB Output isn't correct
31 Incorrect 70 ms 9380 KB Output isn't correct
32 Incorrect 74 ms 9380 KB Output isn't correct
33 Correct 73 ms 9380 KB Output is correct
34 Correct 4 ms 9380 KB Output is correct
35 Correct 4 ms 9380 KB Output is correct
36 Correct 5 ms 9380 KB Output is correct
37 Correct 5 ms 9380 KB Output is correct
38 Incorrect 70 ms 9380 KB Output isn't correct
39 Incorrect 70 ms 9380 KB Output isn't correct
40 Incorrect 80 ms 9380 KB Output isn't correct
41 Correct 63 ms 9380 KB Output is correct
42 Correct 4 ms 9380 KB Output is correct
43 Correct 4 ms 9380 KB Output is correct
44 Correct 4 ms 9380 KB Output is correct
45 Correct 4 ms 9380 KB Output is correct
46 Incorrect 74 ms 9380 KB Output isn't correct
47 Incorrect 71 ms 9380 KB Output isn't correct
48 Incorrect 65 ms 9380 KB Output isn't correct
49 Correct 72 ms 9380 KB Output is correct
50 Correct 4 ms 9380 KB Output is correct
51 Correct 4 ms 9380 KB Output is correct
52 Correct 4 ms 9380 KB Output is correct
53 Correct 4 ms 9380 KB Output is correct
54 Incorrect 69 ms 9380 KB Output isn't correct