답안 #77285

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
77285 2018-09-24T15:52:04 Z tmwilliamlin168 Pipes (BOI13_pipes) C++14
100 / 100
116 ms 54500 KB
#include <bits/stdc++.h>
using namespace std;

//are lls needed?

#define ll long long

const int mxN=1e5;
int n, m, eu[mxN], ev[mxN], d[mxN], qu[mxN-1], qt, nx[mxN];
ll a[mxN], b[mxN];
vector<int> adj[mxN];

void fk() {
	cout << 0;
	exit(0);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	if(m>n)
		fk();
	for(int i=0; i<n; ++i)
		cin >> a[i];
	for(int i=0; i<m; ++i) {
		cin >> eu[i] >> ev[i], --eu[i], --ev[i];
		adj[eu[i]].push_back(i);
		adj[ev[i]].push_back(i);
		++d[eu[i]];
		++d[ev[i]];
	}
	for(int i=0; i<n; ++i)
		if(d[i]==1)
			qu[qt++]=i;
	for(int qh=0; qh<n-1; ++qh) {
		if(qh>=qt) {
			if((n^qh)&1^1)
				fk();
			int u=-1, l=-1;
			while(!d[++u]);
			ll s1=0;
			for(int v=u, w, s2=1; v!=u||l==-1; l=nx[v], v=w, s2=-s2) {
//				cout << "h2 " << v << endl;
				for(int e : adj[v]) {
					nx[v]=e;
					w=v^eu[e]^ev[e];
					if(d[w]&&e!=l)
						break;
				}
				s1+=s2*a[v];
//				cout << s1 << " " << nx[v] << endl;
			}
			b[l]=s1;
			for(int v=u, w; nx[v]!=l; v^=eu[nx[v]]^ev[nx[v]])
				b[nx[v]]=s1=2*a[v]-s1;
			a[0]=0;
			break;
		}
		int u=qu[qh];
//		cout << "h1 " << u << endl;
		for(int e : adj[u]) {
			int v=u^eu[e]^ev[e];
			if(!d[v])
				continue;
			b[e]=2*a[u];
			a[v]-=a[u];
			if(--d[v]==1)
				qu[qt++]=v;
			break;
		}
		d[u]=0;
	}
	if(a[qu[n-1]])
		fk();
	for(int i=0; i<m; ++i)
		cout << b[i] << "\n";
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:39:13: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    if((n^qh)&1^1)
       ~~~~~~^~
pipes.cpp:56:17: warning: unused variable 'w' [-Wunused-variable]
    for(int v=u, w; nx[v]!=l; v^=eu[nx[v]]^ev[nx[v]])
                 ^
pipes.cpp:44:27: warning: 'w' may be used uninitialized in this function [-Wmaybe-uninitialized]
    for(int v=u, w, s2=1; v!=u||l==-1; l=nx[v], v=w, s2=-s2) {
                          ~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2808 KB Output is correct
2 Correct 4 ms 2896 KB Output is correct
3 Correct 4 ms 2984 KB Output is correct
4 Correct 86 ms 11260 KB Output is correct
5 Correct 4 ms 11260 KB Output is correct
6 Correct 4 ms 11260 KB Output is correct
7 Correct 4 ms 11260 KB Output is correct
8 Correct 7 ms 11260 KB Output is correct
9 Correct 4 ms 11260 KB Output is correct
10 Correct 5 ms 11260 KB Output is correct
11 Correct 5 ms 11260 KB Output is correct
12 Correct 5 ms 11260 KB Output is correct
13 Correct 67 ms 11500 KB Output is correct
14 Correct 78 ms 14000 KB Output is correct
15 Correct 87 ms 15864 KB Output is correct
16 Correct 73 ms 16288 KB Output is correct
17 Correct 93 ms 18852 KB Output is correct
18 Correct 93 ms 20424 KB Output is correct
19 Correct 101 ms 21968 KB Output is correct
20 Correct 4 ms 21968 KB Output is correct
21 Correct 6 ms 21968 KB Output is correct
22 Correct 84 ms 23644 KB Output is correct
23 Correct 66 ms 23644 KB Output is correct
24 Correct 81 ms 26348 KB Output is correct
25 Correct 84 ms 26644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 26644 KB Output is correct
2 Correct 6 ms 26644 KB Output is correct
3 Correct 71 ms 28352 KB Output is correct
4 Correct 5 ms 28352 KB Output is correct
5 Correct 4 ms 28352 KB Output is correct
6 Correct 4 ms 28352 KB Output is correct
7 Correct 4 ms 28352 KB Output is correct
8 Correct 4 ms 28352 KB Output is correct
9 Correct 5 ms 28352 KB Output is correct
10 Correct 4 ms 28352 KB Output is correct
11 Correct 4 ms 28352 KB Output is correct
12 Correct 4 ms 28352 KB Output is correct
13 Correct 4 ms 28352 KB Output is correct
14 Correct 5 ms 28352 KB Output is correct
15 Correct 5 ms 28352 KB Output is correct
16 Correct 4 ms 28352 KB Output is correct
17 Correct 4 ms 28352 KB Output is correct
18 Correct 4 ms 28352 KB Output is correct
19 Correct 4 ms 28352 KB Output is correct
20 Correct 4 ms 28352 KB Output is correct
21 Correct 4 ms 28352 KB Output is correct
22 Correct 5 ms 28352 KB Output is correct
23 Correct 71 ms 29444 KB Output is correct
24 Correct 95 ms 32336 KB Output is correct
25 Correct 70 ms 32776 KB Output is correct
26 Correct 4 ms 32776 KB Output is correct
27 Correct 4 ms 32776 KB Output is correct
28 Correct 4 ms 32776 KB Output is correct
29 Correct 4 ms 32776 KB Output is correct
30 Correct 98 ms 35340 KB Output is correct
31 Correct 99 ms 36880 KB Output is correct
32 Correct 96 ms 38740 KB Output is correct
33 Correct 68 ms 39384 KB Output is correct
34 Correct 4 ms 39384 KB Output is correct
35 Correct 4 ms 39384 KB Output is correct
36 Correct 4 ms 39384 KB Output is correct
37 Correct 4 ms 39384 KB Output is correct
38 Correct 93 ms 41896 KB Output is correct
39 Correct 83 ms 43600 KB Output is correct
40 Correct 88 ms 45088 KB Output is correct
41 Correct 66 ms 45636 KB Output is correct
42 Correct 4 ms 45636 KB Output is correct
43 Correct 4 ms 45636 KB Output is correct
44 Correct 4 ms 45636 KB Output is correct
45 Correct 5 ms 45636 KB Output is correct
46 Correct 84 ms 48184 KB Output is correct
47 Correct 116 ms 49900 KB Output is correct
48 Correct 99 ms 51336 KB Output is correct
49 Correct 74 ms 51852 KB Output is correct
50 Correct 4 ms 51852 KB Output is correct
51 Correct 4 ms 51852 KB Output is correct
52 Correct 4 ms 51852 KB Output is correct
53 Correct 4 ms 51852 KB Output is correct
54 Correct 111 ms 54500 KB Output is correct