Submission #111628

# Submission time Handle Problem Language Result Execution time Memory
111628 2019-05-15T21:47:51 Z wilwxk Pipes (BOI13_pipes) C++11
70.1852 / 100
427 ms 45048 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN=1e5+5;
vector<int> g[MAXN], lista[MAXN];
vector<int> ncyc;
ll v[MAXN], tenho[MAXN];
int gin[MAXN];
ll resp[MAXN], soma;
int n, m;

void poda() {
	queue<int> qu;
	for(int i=1; i<=n; i++) if(gin[i]==1) qu.push(i);
	while(!qu.empty()) {
		int cur=qu.front(); qu.pop();
		gin[cur]=0; ncyc.push_back(cur);
		for(int i=0; i<g[cur].size(); i++) {
			int viz=g[cur][i]; int ind=lista[cur][i];
			if(!gin[viz]) continue;
			gin[viz]--;
			if(gin[viz]<=1) qu.push(viz);
			resp[ind]=v[cur]-tenho[cur];
			tenho[viz]+=resp[ind];
			tenho[cur]+=resp[ind];
			// printf("%d -> %d (%d, %lld)\n", cur, viz, ind, tenho[cur]);
		}
	}
}

void dfs(int cur, int k) {
	// printf("%d %d\n", cur, k);
	gin[cur]=1;
	for(int i=0; i<g[cur].size(); i++) {
		int viz=g[cur][i]; int ind=lista[cur][i];
		if(gin[viz]!=2) continue;
		dfs(viz, k^1);
	}
	if(!k) soma+=tenho[cur];
	else soma-=tenho[cur];
}

void solve(int cur, int p) {
	gin[cur]=2;
	for(int i=0; i<g[cur].size(); i++) {
		int viz=g[cur][i]; int ind=lista[cur][i];
		if(viz==p||gin[viz]!=1) continue;
		if(cur==p) resp[ind]=soma;
		else resp[ind]=v[cur]-tenho[cur];
		tenho[viz]+=soma;
		// tenho[cur]+=soma;
		solve(viz, cur);
	}
}

int main() {
	scanf("%d %d", &n, &m);
	for(int i=1; i<=n; i++) scanf("%lld", &v[i]), v[i]*=2;
	for(int i=1; i<=m; i++) {
		int a, b; scanf("%d %d", &a, &b);
		g[a].push_back(b); g[b].push_back(a);
		gin[a]++; gin[b]++;
		lista[a].push_back(i); lista[b].push_back(i);
	}

	poda();
	for(int i=1; i<=n; i++) if(gin[i]) v[i]-=tenho[i], tenho[i]=0;
	// for(int i=1; i<=n; i++) cout << v[i] << endl;

	if(m>n||(n-ncyc.size())%2==0) {
		printf("0\n");
		return 0;
	}
	if(m==n-1&&tenho[ncyc.back()]!=v[ncyc.back()]) {
		printf("0\n");
		return 0;
	}

	for(int i=1; i<=n; i++) {
		if(!gin[i]) continue;
		dfs(i, 1);	
		// printf("ok %lld\n", soma);
		solve(i, i);
		break;
	}

	for(int i=1; i<=m; i++) printf("%lld\n", resp[i]);

}

Compilation message

pipes.cpp: In function 'void poda()':
pipes.cpp:19:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0; i<g[cur].size(); i++) {
                ~^~~~~~~~~~~~~~
pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:35:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<g[cur].size(); i++) {
               ~^~~~~~~~~~~~~~
pipes.cpp:36:26: warning: unused variable 'ind' [-Wunused-variable]
   int viz=g[cur][i]; int ind=lista[cur][i];
                          ^~~
pipes.cpp: In function 'void solve(int, int)':
pipes.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<g[cur].size(); i++) {
               ~^~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:58: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:59:46: 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", &v[i]), v[i]*=2;
                          ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
pipes.cpp:61:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d %d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 40 ms 5120 KB Output is correct
4 Correct 164 ms 15496 KB Output is correct
5 Correct 6 ms 4992 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Correct 6 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 7 ms 5092 KB Output is correct
11 Correct 7 ms 5120 KB Output is correct
12 Correct 8 ms 5120 KB Output is correct
13 Correct 99 ms 13268 KB Output is correct
14 Correct 115 ms 14764 KB Output is correct
15 Correct 142 ms 15396 KB Output is correct
16 Correct 94 ms 13936 KB Output is correct
17 Correct 123 ms 15412 KB Output is correct
18 Correct 122 ms 15376 KB Output is correct
19 Correct 159 ms 15072 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 6 ms 5120 KB Output is correct
22 Correct 199 ms 15428 KB Output is correct
23 Correct 123 ms 13296 KB Output is correct
24 Correct 151 ms 15336 KB Output is correct
25 Correct 135 ms 13680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 5120 KB Output isn't correct
2 Incorrect 7 ms 5120 KB Output isn't correct
3 Correct 119 ms 14212 KB Output is correct
4 Correct 128 ms 14436 KB Output is correct
5 Correct 124 ms 14680 KB Output is correct
6 Runtime error 427 ms 45048 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Incorrect 5 ms 4992 KB Output isn't correct
8 Incorrect 5 ms 4992 KB Output isn't correct
9 Correct 6 ms 5040 KB Output is correct
10 Correct 5 ms 4992 KB Output is correct
11 Correct 5 ms 4992 KB Output is correct
12 Correct 5 ms 4992 KB Output is correct
13 Correct 6 ms 4992 KB Output is correct
14 Incorrect 6 ms 4992 KB Output isn't correct
15 Incorrect 7 ms 5248 KB Output isn't correct
16 Incorrect 7 ms 5120 KB Output isn't correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 6 ms 5120 KB Output is correct
21 Correct 7 ms 5248 KB Output is correct
22 Incorrect 8 ms 5248 KB Output isn't correct
23 Incorrect 142 ms 16416 KB Output isn't correct
24 Incorrect 182 ms 18324 KB Output isn't correct
25 Correct 127 ms 14072 KB Output is correct
26 Correct 128 ms 14404 KB Output is correct
27 Correct 153 ms 14196 KB Output is correct
28 Correct 152 ms 14720 KB Output is correct
29 Runtime error 413 ms 40480 KB Execution killed with signal 11 (could be triggered by violating memory limits)
30 Incorrect 213 ms 17512 KB Output isn't correct
31 Incorrect 232 ms 20176 KB Output isn't correct
32 Incorrect 159 ms 16372 KB Output isn't correct
33 Correct 120 ms 14584 KB Output is correct
34 Correct 99 ms 14304 KB Output is correct
35 Correct 97 ms 14328 KB Output is correct
36 Correct 102 ms 14708 KB Output is correct
37 Runtime error 418 ms 44840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Incorrect 170 ms 17804 KB Output isn't correct
39 Incorrect 157 ms 16068 KB Output isn't correct
40 Incorrect 149 ms 17952 KB Output isn't correct
41 Correct 97 ms 14316 KB Output is correct
42 Correct 96 ms 14000 KB Output is correct
43 Correct 107 ms 14088 KB Output is correct
44 Correct 120 ms 14844 KB Output is correct
45 Correct 266 ms 18936 KB Output is correct
46 Incorrect 173 ms 17396 KB Output isn't correct
47 Incorrect 167 ms 18228 KB Output isn't correct
48 Incorrect 213 ms 19964 KB Output isn't correct
49 Correct 125 ms 14432 KB Output is correct
50 Correct 123 ms 14584 KB Output is correct
51 Correct 122 ms 14684 KB Output is correct
52 Correct 112 ms 14172 KB Output is correct
53 Correct 396 ms 19528 KB Output is correct
54 Incorrect 165 ms 17164 KB Output isn't correct