zoukankan      html  css  js  c++  java
  • 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
    ", cas, ans);
    52     }
    53     
    54     return 0;
    55 }
    View Code
  • 相关阅读:
    JSOI2010 满汉全席
    LNOI2014 LCA
    BZOJ3689 异或之
    Codeforces Round #553 div.2
    AHOI2013 差异
    SDOI2016 生成魔咒
    NOI2006 最大获利
    没有过的题QAQ
    NOI2014 动物园
    HDU4622 Reincarnation
  • 原文地址:https://www.cnblogs.com/showson/p/5077097.html
Copyright © 2011-2022 走看看