BZOJ1907 Tree path cover greedy __ Greedy

Source: Internet
Author: User

"Topic link"

Empty time forget to empty the Edge = =re countless hair

In addition to calculate the time to calculate the root node ...

"The YDC."

/* Thank Thunk * * #include <cstdio> #include <cstring> #include <algorithm> using namespace std;

const int MAXN = 10005;

int n, HEAD[MAXN], CNT, Q[MAXN], DP[MAXN], PRE[MAXN];

struct _edge {int V, next;} G[MAXN << 1];
	inline int iread () {int f = 1, x = 0; char ch = getchar (); for (; Ch < ' 0 ' | | | ch > ' 9 '; ch = getchar ()) F = ch = = '-'?
	-1:1;
	for (; Ch >= ' 0 ' && ch <= ' 9 '; ch = getchar ()) x = x * + ch-' 0 ';
return f * x;
	} inline void Add (int u, int v) {g[cnt] = (_edge) {V, head[u]};
Head[u] = cnt++; int main () {for (int T = Iread (); T
		t--) {n = iread (); for (int i = 1; I <= n; i++) Head[i] =-1, dp[i] = pre[i] = Q[i] = 0;
		CNT = 0;
			for (int i = 1; i < n; i++) {int u = iread (), V = iread (); Add (U, v);
		Add (V, u);
		int h = 0, t = 0;
		pre[q[t++] = 1] = n + 1;
			while (H!= t) {int u = q[h++];
		for (int i = head[u]; ~i i = g[i].next) if (!PRE[G[I].V]) pre[q[t++] = g[i].v] = u; } INT ans = n;
			for (int i = t-1; ~i; i--) {int u = q[i];
			if (dp[u] = = 0) dp[pre[u]]++;
			else if (dp[u] = = 1) ans--, dp[pre[u]]++;
		else ans-= 2;
	printf ("%d\n", ans);
return 0;
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.