Submission #111619

# Submission time Handle Problem Language Result Execution time Memory
111619 2019-05-15T18:00:01 Z rajarshi_basu Pipes (BOI13_pipes) C++14
74.0741 / 100
377 ms 10884 KB
#include <iostream>
#include <vector>
#include <set>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <complex>
#include <stack>
#include <set>

#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define cd complex<double> 

const int INF = 1e9;
using namespace std;
const int MAXN = 100*1000 +5;

int nodeVal[MAXN];
int edgesVal[MAXN];
bool marked[MAXN];
vector<ii> g[MAXN];

stack<int> st;
bool vis[MAXN];
void markCycle(int node,int p){
	st.push(node);
	if(vis[node]){
		while(!st.empty()){
			int e = st.top();st.pop();
			marked[e] = 1;
		}
	}else{
		vis[node] = 1;
		for(auto e:g[node]){
			if(e.ff != p){
				markCycle(e.ff,node);
			}
		}
	}
	if(!st.empty())st.pop();
}

void dfs(int node,int p,int pe){
	for(auto e:g[node]){
		if(e.ff != p and !marked[e.ff]){
			dfs(e.ff,node,e.ss);
			nodeVal[node] -= nodeVal[e.ff];
		}
	}
	if(pe > -1){
		edgesVal[pe] = nodeVal[node];
	}
}

int main(){
	int n,m;
	cin >> n >> m;
	if(m > n){
		cout << "0" << endl;
	}else if(m < n){
		FOR(i,n)cin >> nodeVal[i];
		FOR(i,m){
			int a,b;
			cin >> a >> b;
			a--;b--;
			g[a].pb({b,i});
			g[b].pb({a,i});
		}
		dfs(0,-1,-1);
		FOR(i,m){
			cout << 2*edgesVal[i] << endl;
		}
	}else{
		markCycle(0,-1);
		int cnt = 0;
		FOR(i,n){
			if(marked[i]){
				dfs(i,-1,-1);
				cnt++;
			}
		}
		if(cnt%2 == 0){
			cout << 0 << endl;
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 8 ms 2816 KB Output is correct
4 Correct 309 ms 7584 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 5 ms 2688 KB Output is correct
7 Correct 6 ms 2788 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 7 ms 2816 KB Output is correct
10 Correct 7 ms 2688 KB Output is correct
11 Correct 6 ms 2816 KB Output is correct
12 Correct 6 ms 2816 KB Output is correct
13 Correct 290 ms 6580 KB Output is correct
14 Correct 311 ms 7608 KB Output is correct
15 Correct 377 ms 7928 KB Output is correct
16 Correct 265 ms 6904 KB Output is correct
17 Correct 304 ms 7632 KB Output is correct
18 Correct 318 ms 7880 KB Output is correct
19 Correct 309 ms 10884 KB Output is correct
20 Correct 5 ms 2688 KB Output is correct
21 Correct 7 ms 2688 KB Output is correct
22 Correct 276 ms 7672 KB Output is correct
23 Correct 219 ms 6648 KB Output is correct
24 Correct 296 ms 7676 KB Output is correct
25 Correct 220 ms 6772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2688 KB Output isn't correct
2 Incorrect 4 ms 2688 KB Output isn't correct
3 Correct 5 ms 2688 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 5 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Incorrect 5 ms 2688 KB Output isn't correct
8 Incorrect 4 ms 2688 KB Output isn't correct
9 Correct 5 ms 2660 KB Output is correct
10 Correct 5 ms 2688 KB Output is correct
11 Correct 5 ms 2688 KB Output is correct
12 Correct 4 ms 2688 KB Output is correct
13 Correct 4 ms 2688 KB Output is correct
14 Incorrect 5 ms 2688 KB Output isn't correct
15 Incorrect 4 ms 2688 KB Output isn't correct
16 Incorrect 5 ms 2688 KB Output isn't correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 5 ms 2688 KB Output is correct
19 Correct 4 ms 2732 KB Output is correct
20 Correct 5 ms 2688 KB Output is correct
21 Correct 5 ms 2688 KB Output is correct
22 Incorrect 4 ms 2688 KB Output isn't correct
23 Incorrect 4 ms 2688 KB Output isn't correct
24 Incorrect 4 ms 2688 KB Output isn't correct
25 Correct 5 ms 2688 KB Output is correct
26 Correct 4 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 4 ms 2688 KB Output is correct
30 Incorrect 5 ms 2688 KB Output isn't correct
31 Incorrect 4 ms 2688 KB Output isn't correct
32 Incorrect 4 ms 2688 KB Output isn't correct
33 Correct 5 ms 2688 KB Output is correct
34 Correct 5 ms 2660 KB Output is correct
35 Correct 4 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 4 ms 2688 KB Output is correct
38 Incorrect 5 ms 2688 KB Output isn't correct
39 Incorrect 4 ms 2688 KB Output isn't correct
40 Incorrect 4 ms 2688 KB Output isn't correct
41 Correct 4 ms 2688 KB Output is correct
42 Correct 5 ms 2688 KB Output is correct
43 Correct 4 ms 2688 KB Output is correct
44 Correct 5 ms 2688 KB Output is correct
45 Correct 4 ms 2688 KB Output is correct
46 Incorrect 4 ms 2688 KB Output isn't correct
47 Incorrect 5 ms 2688 KB Output isn't correct
48 Incorrect 5 ms 2688 KB Output isn't correct
49 Correct 4 ms 2688 KB Output is correct
50 Correct 4 ms 2688 KB Output is correct
51 Correct 4 ms 2688 KB Output is correct
52 Correct 4 ms 2688 KB Output is correct
53 Correct 5 ms 2688 KB Output is correct
54 Incorrect 4 ms 2688 KB Output isn't correct