UVaLive6039 Uva1668 Let's Go Green

一开始考虑所有边都是单独的一条路径

然后尽量多的合并

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<algorithm>
 5 #include<iostream>
 6
 7 using namespace std;
 8
 9 void setIO(const string& s) {
10     freopen((s + ".in").c_str(), "r", stdin);
11     freopen((s + ".out").c_str(), "w", stdout);
12 }
13 template<typename Q> Q read(Q& x) {
14     static char c, f;
15     for(f = 0; c = getchar(), !isdigit(c); ) if(c == ‘-‘) f = 1;
16     for(x = 0; isdigit(c); c = getchar()) x = x * 10 + c - ‘0‘;
17     if(f) x = -x;
18     return x;
19 }
20 template<typename Q> Q read() {
21     static Q x; read(x); return x;
22 }
23
24 const int N = 100000 + 10;
25 int main() {
26 #ifdef DEBUG
27     freopen("in.txt", "r", stdin);
28     freopen("out.txt", "w", stdout);
29 #endif
30
31     static int du[N], mx[N];
32     int T = read<int>();
33     for(int cas = 1; cas <= T; cas++) {
34         memset(du, 0, sizeof du);
35         memset(mx, 0, sizeof mx);
36         int ans = 0;
37         int u, v, w, n = read<int>();
38         for(int i = 1; i < n; i++) {
39             read(u), read(v), read(w);
40             du[u] += w, du[v] += w;
41             mx[u] = max(mx[u], w);
42             mx[v] = max(mx[v], w);
43             ans += w;
44         }
45
46         for(int u = 1; u <= n; u++) {
47             if((mx[u] << 1) <= du[u]) ans -= du[u] >> 1;
48             else ans -= du[u] - mx[u];
49         }
50
51         printf("Case #%d: %d\n", cas, ans);
52     }
53
54     return 0;
55 }

UVaLive6039 Uva1668 Let's Go Green

时间: 2024-12-12 01:05:41

UVaLive6039 Uva1668 Let's Go Green的相关文章

Eclipse UML插件Green UML、AmaterasUML

一.Green UML插件 1.查看Eclipse版本 查看当前电脑上安装的Eclipse版本(Help-About Eclipse Platform),是3.3.2版本的. 2.查看相应插件版本 然后去网站http://green.sourceforge.net/builds.html上查看相对应的Green以及GEF版本: 好像是Green3.0.0以及GEF3.3 3.安装Green 3.0.0 只要在上述网站中直接点击3.0.0的链接即可.将下载到的green-3.0.0.zip解压,将

21 Guns -- Green Day

21 Guns Green Day (绿日乐队)的代表曲之一.歌曲的主题是反战,同时安慰了曾 经信任布什政府如今失望透顶的美国民众.这首歌也被电影<变形金刚2> 当作插曲. Do you know what's worth fighting for When it's not worth dying for? Does it take your breath away And you feel yourself suffocating1?Does the pain weigh out the

分形之概率学下的green tree

     今天做的是分形之随机概率,可以和以前做的那个抛色子的做法非常相似,抛色子是用随机点数控制图形,今天做的树叶图形只是用概率的做法去控制图形而已,做法是如出一辙的: //图形界面 package tree0618; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.Graphics2D: import javax.swing.JFrame; public

[2015-12-25]OMG美语每日笔记-Go green

坚持学习英语,OMG口语非常长不错,坚持每天整理.学英语坚持最重要,学英语坚持最重要,学英语坚持最重要说三遍! Go green  环保生活 I've been thinking about ways I cloud go green .What can I do to be more environmentally friendly? 我最近在想怎样才能过绿色生活?我应该怎么才能更环保呢? reuse 循环使用 One way I've gone green is by reusing pla

Supra Indy Ns Mid Tops Blue Lime Green Mens is now available at a reduced price in the US

an ancient empire mostly located in Mesopotamia. A recent study has shown that it was probably overpopulation and drought that led to the collapse of the Assyrian civilisation.Karkemish, which flourished along the Euphrates dates back to more than 5,

Green Thread

What is Green Thread. wiki http://en.wikipedia.org/wiki/Green_threads The Wikipedia article Green Threads explains it very well. In a nutshell, Green threads are "user-level threads". They are scheduled by an "ordinary" user-level proc

Green the world :使用monkey_patch

eventlet的monkey_patch 用于绿化一些python的模块,看看以下的样例就明确了 urls = ["http://www.haha.mx/joke/1292935", "http://www.baidu.com"] import eventlet from eventlet.green import urllib2 import time def fetch(url): try: print "opening0", url ti

Derive representation formula from Green’s identity

This article introduces how to derive the representation formula used in BEM from Green's identity. Interior and exterior representation formulas Let $u$ be a harmonic function in the free space $\mathbb{R}^d$: \begin{equation} \label{eq:harmonic-fun

【BZOJ 2688】 2688: Green Hackenbush (概率DP+博弈-树上删边)

2688: Green Hackenbush Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 42  Solved: 16 Description 有一个古老的游戏叫做Green Hackenbush,游戏是这样进行的:两个人轮流在一棵树上删边,每次删边后不与根联通的子树直接被ignore,不能删边的游戏者输.Alice和Bob也在玩这个游戏,不过他们面对的是n棵树,第i棵树是含有a[i]个节点的二叉树.先手的Alice想知道自己有多大的概率获胜(