답안 #535159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535159 2022-03-09T14:23:43 Z faik Pipes (BOI13_pipes) C++14
36.2963 / 100
81 ms 12936 KB
#include <bits/stdc++.h>

using namespace std;

#define MOD 998244353
#define INF 1000000001
#define LNF 1000000000000000001

#define int ll

typedef long long ll;
typedef pair<int,int> pii;

void solve(){
//#define TEST
	int n,m;cin >> n >> m;
	if(m > n){
		cout << "0";
		return;
	}
	vector<int> net(n);
	for(int i = 0;i < n;i++){
		cin >> net[i];
	}
	vector<int> ret(m);
	vector<vector<pii>> edge(n);
	for(int i = 0;i < m;i++){
		int a,b;cin >> a >> b;
		edge[a].emplace_back(b,i);
		edge[b].emplace_back(a,i);
	}
	stack<int> leaf;
	vector<int> sizes(n);
	vector<int> removed(n);
	for(int i = 0;i < n;i++){
		sizes[i] = edge[i].size();
		if(edge[i].size() == 1){
			leaf.push(i);
		}
	}
	while(!leaf.empty()){	
		int top = leaf.top();
		leaf.pop();
		removed[top] = true;
		pii parent;
		for(auto i : edge[top]){
			if(!removed[i.first])
				parent = i;
		}
		ret[parent.second] = -net[top]*2;
		sizes[top]--;
		sizes[parent.first]--;
		if(sizes[parent.first] == 1){
			leaf.push(parent.first);
		}
	}
	int left = 0;
	for(int i = 0;i < n;i++){
		if(!removed[i])
			left++;
	}
	if(left == 0){
		for(int i : ret)
			cout << i << ' ';
		return;
	} else if(left%2 == 0){
		cout << '0';
		return;
	}
	
	
	
}

signed main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
#ifdef DEBUG
	freopen("i.txt","r",stdin);
	freopen("o.txt","w",stdout);
#endif
	int t = 1;
#ifdef TEST
	cin >> t;
#endif
	while(t--){
		solve();
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 440 KB Execution killed with signal 11
2 Runtime error 1 ms 432 KB Execution killed with signal 11
3 Runtime error 2 ms 556 KB Execution killed with signal 11
4 Incorrect 54 ms 12808 KB Output isn't correct
5 Runtime error 1 ms 420 KB Execution killed with signal 11
6 Runtime error 1 ms 460 KB Execution killed with signal 11
7 Runtime error 1 ms 460 KB Execution killed with signal 11
8 Runtime error 1 ms 460 KB Execution killed with signal 11
9 Runtime error 3 ms 708 KB Execution killed with signal 6
10 Runtime error 1 ms 584 KB Execution killed with signal 11
11 Runtime error 1 ms 460 KB Execution killed with signal 11
12 Runtime error 3 ms 588 KB Execution killed with signal 6
13 Incorrect 39 ms 10184 KB Output isn't correct
14 Incorrect 50 ms 12088 KB Output isn't correct
15 Incorrect 60 ms 12936 KB Output isn't correct
16 Incorrect 44 ms 10924 KB Output isn't correct
17 Incorrect 53 ms 12776 KB Output isn't correct
18 Incorrect 63 ms 12876 KB Output isn't correct
19 Incorrect 77 ms 12472 KB Output isn't correct
20 Runtime error 1 ms 452 KB Execution killed with signal 11
21 Runtime error 1 ms 572 KB Execution killed with signal 11
22 Incorrect 55 ms 12860 KB Output isn't correct
23 Incorrect 40 ms 10272 KB Output isn't correct
24 Incorrect 81 ms 12836 KB Output isn't correct
25 Incorrect 49 ms 10708 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Runtime error 1 ms 448 KB Execution killed with signal 11
3 Incorrect 43 ms 12024 KB Output isn't correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Runtime error 1 ms 460 KB Execution killed with signal 11
8 Runtime error 2 ms 588 KB Execution killed with signal 6
9 Runtime error 1 ms 428 KB Execution killed with signal 11
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Runtime error 1 ms 460 KB Execution killed with signal 11
15 Runtime error 1 ms 448 KB Execution killed with signal 11
16 Runtime error 1 ms 460 KB Execution killed with signal 11
17 Runtime error 1 ms 576 KB Execution killed with signal 11
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Runtime error 1 ms 588 KB Execution killed with signal 11
23 Incorrect 37 ms 10436 KB Output isn't correct
24 Incorrect 47 ms 12768 KB Output isn't correct
25 Incorrect 60 ms 12040 KB Output isn't correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 312 KB Output is correct
30 Incorrect 48 ms 12192 KB Output isn't correct
31 Incorrect 49 ms 12528 KB Output isn't correct
32 Incorrect 59 ms 12848 KB Output isn't correct
33 Correct 51 ms 12680 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 324 KB Output is correct
36 Correct 1 ms 324 KB Output is correct
37 Correct 1 ms 316 KB Output is correct
38 Incorrect 62 ms 12648 KB Output isn't correct
39 Incorrect 55 ms 12736 KB Output isn't correct
40 Incorrect 45 ms 12724 KB Output isn't correct
41 Incorrect 49 ms 12508 KB Output isn't correct
42 Correct 1 ms 320 KB Output is correct
43 Correct 1 ms 284 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 324 KB Output is correct
46 Incorrect 56 ms 12472 KB Output isn't correct
47 Incorrect 43 ms 12740 KB Output isn't correct
48 Incorrect 41 ms 12596 KB Output isn't correct
49 Incorrect 55 ms 12048 KB Output isn't correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 328 KB Output is correct
53 Correct 1 ms 300 KB Output is correct
54 Incorrect 52 ms 12468 KB Output isn't correct