Submission #110761

# Submission time Handle Problem Language Result Execution time Memory
110761 2019-05-12T07:55:45 Z ckodser Pipes (BOI13_pipes) C++14
30 / 100
160 ms 25332 KB
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 100005;
int n, m, cv, cu, A[N], B[N], M[N], P[N], R[N];
ll C[N], D[N];
vector < int > Adj[N];
void DFSC(int v, int p)
{
	M[v] = 1;
	for (int id : Adj[v])
		if (id != p)
		{
			int u = A[id] ^ B[id] ^ v;
			if (M[u])
				cv = v, cu = u;
			if (!M[u])
				P[u] = v, DFSC(u, id);
		}
}
void DFS(int v, int p)
{
	for (int id : Adj[v])
		if (id != p)
			DFS(A[id] ^ B[id] ^ v, id);
	int par = A[p] ^ B[p] ^ v;
	D[p] += C[v] + C[v];
	C[par] -= C[v];
	C[v] = 0;
}
void DFS2(int v, int p)
{
	M[v] = 2;
	P[v] = p;
	R[v] = Adj[v][0] ^ Adj[v][1] ^ p;
	int u = A[R[v]] ^ B[R[v]] ^ v;
	if (M[u] != 2)
		DFS2(u, R[v]);
}
int main()
{
	scanf("%d%d", &n, &m);
	if (m > n) assert(0);
	for (int i = 1; i <= n; i++)
		scanf("%lld", &C[i]);
	for (int i = 1; i <= m; i++)
	{
		scanf("%d%d", &A[i], &B[i]);
		Adj[A[i]].pb(i);
		Adj[B[i]].pb(i);
	}
	DFSC(1, 0);
	if (!cv)
		cv = cu = 1;
	vector < int > vec;
	vec.pb(cu);
	while (cv != cu)
		cu = P[cu], vec.pb(cu);
	if ((int)vec.size() % 2 == 0)
		assert(0);
	memset(M, 0, sizeof(M));
	for (int v : vec)
		M[v] = 1;
	for (int v : vec)
		for (int id : Adj[v])
		{
			int u = A[id] ^ B[id] ^ v;
			if (!M[u]) DFS(u, id);
		}
	if (vec.size() > 1)
	{
		for (int v : vec)
			for (int i = 0; i < (int)Adj[v].size(); i++)
			{
				int id = Adj[v][i];
				if (!M[A[id] ^ B[id] ^ v])
					swap(Adj[v][i], Adj[v].back()), Adj[v].pop_back(), i --;
			}
		int idd = Adj[vec[0]][0];
		if ((A[idd] ^ B[idd] ^ vec[0]) != vec[1])
			DFS2(vec[0], Adj[vec[0]][0]);
		else
			DFS2(vec[0], Adj[vec[0]][1]);
		vector < ll > Df(vec.size(), 0);
		for (int i = 2; i != 0; i = (i + 2) % (int)vec.size())
		{
			int p1 = i - 1;
			int p2 = i - 2;
			if (p1 < 0)
				p1 = (int)vec.size() - 1;
			if (p2 < 0)
				p2 = (int)vec.size() - 1;
			Df[i] = Df[i] - C[vec[p2]] + C[vec[p1]];
		}
		ll sum = 0;
		for (int i = 0; i < (int)vec.size(); i++)
			sum += C[vec[i]];
		sum /= 2;
		for (int i = 0; i < (int)vec.size(); i++)
			sum -= Df[i];
		sum /= (int)vec.size();
		for (int i = 0; i < (int)vec.size(); i++)
			D[P[vec[i]]] += sum + Df[i];
	}
	for (int i = 1; i <= m; i++)
		printf("%lld\n", D[i]);
	return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:43: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:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &C[i]);
   ~~~~~^~~~~~~~~~~~~~~
pipes.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &A[i], &B[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3072 KB Output is correct
2 Correct 5 ms 3072 KB Output is correct
3 Correct 5 ms 3200 KB Output is correct
4 Correct 117 ms 9520 KB Output is correct
5 Correct 5 ms 3072 KB Output is correct
6 Correct 4 ms 3072 KB Output is correct
7 Correct 4 ms 3072 KB Output is correct
8 Correct 5 ms 3072 KB Output is correct
9 Correct 5 ms 3072 KB Output is correct
10 Correct 5 ms 3200 KB Output is correct
11 Correct 5 ms 3144 KB Output is correct
12 Correct 6 ms 3200 KB Output is correct
13 Correct 103 ms 8184 KB Output is correct
14 Correct 117 ms 9080 KB Output is correct
15 Correct 129 ms 9464 KB Output is correct
16 Correct 95 ms 8560 KB Output is correct
17 Correct 122 ms 9464 KB Output is correct
18 Correct 112 ms 9464 KB Output is correct
19 Correct 151 ms 11688 KB Output is correct
20 Correct 5 ms 3044 KB Output is correct
21 Correct 5 ms 3072 KB Output is correct
22 Correct 107 ms 9464 KB Output is correct
23 Correct 89 ms 8184 KB Output is correct
24 Correct 133 ms 9476 KB Output is correct
25 Correct 118 ms 8352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3072 KB Output isn't correct
2 Incorrect 6 ms 3200 KB Output isn't correct
3 Runtime error 109 ms 20472 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 8 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 8 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Incorrect 5 ms 3072 KB Output isn't correct
8 Incorrect 5 ms 3072 KB Output isn't correct
9 Runtime error 8 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 7 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 8 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 8 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 7 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Incorrect 5 ms 3072 KB Output isn't correct
15 Incorrect 4 ms 3200 KB Output isn't correct
16 Incorrect 5 ms 3172 KB Output isn't correct
17 Runtime error 7 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 8 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 7 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Runtime error 8 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Incorrect 5 ms 3200 KB Output isn't correct
23 Incorrect 109 ms 11420 KB Output isn't correct
24 Incorrect 160 ms 12684 KB Output isn't correct
25 Runtime error 103 ms 20444 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
27 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
29 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
30 Incorrect 159 ms 14100 KB Output isn't correct
31 Incorrect 154 ms 14576 KB Output isn't correct
32 Incorrect 127 ms 10868 KB Output isn't correct
33 Runtime error 145 ms 22128 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Runtime error 7 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
35 Runtime error 9 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Runtime error 7 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Incorrect 149 ms 13580 KB Output isn't correct
39 Incorrect 160 ms 10560 KB Output isn't correct
40 Incorrect 160 ms 12580 KB Output isn't correct
41 Runtime error 120 ms 25332 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Runtime error 7 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
43 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Runtime error 8 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
45 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
46 Incorrect 159 ms 14644 KB Output isn't correct
47 Incorrect 134 ms 12500 KB Output isn't correct
48 Incorrect 159 ms 14424 KB Output isn't correct
49 Runtime error 100 ms 17244 KB Execution killed with signal 11 (could be triggered by violating memory limits)
50 Runtime error 8 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
51 Runtime error 7 ms 5120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
52 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Runtime error 7 ms 5248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
54 Incorrect 136 ms 13144 KB Output isn't correct