青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

oyjpArt ACM/ICPC算法程序設計空間

// I am new in programming, welcome to my blog
I am oyjpart(alpc12, 四城)
posts - 224, comments - 694, trackbacks - 0, articles - 6

中南賽A題 Accumulation Degree

Posted on 2008-05-05 20:59 oyjpart 閱讀(3083) 評論(9)  編輯 收藏 引用 所屬分類: ACM/ICPC或其他比賽
Accumulation Degree
Time Limit: 5000MS
Memory Limit: 65536K
Total Submissions: 248
Accepted: 30

Description

Trees are an important component of the natural landscape because of their prevention of erosion and the provision of a specific ather-sheltered ecosystem in and under their foliage. Trees have also been found to play an important role in producing oxygen and reducing carbon dioxide in the atmosphere, as well as moderating ground temperatures. They are also significant elements in landscaping and agriculture, both for their aesthetic appeal and their orchard crops (such as apples). Wood from trees is a common building material.

Trees also play an intimate role in many of the world's mythologies. Many scholars are interested in finding peculiar properties about trees, such as the center of a tree, tree counting, tree coloring. A(x) is one of such properties.

A(x) (accumulation degree of node x) is defined as follows:

  1. Each edge of the tree has an positive capacity.
  2. The nodes with degree of one in the tree are named terminals.
  3. The flow of each edge can't exceed its capacity.
  4. A(x) is the maximal flow that node x can flow to other terminal nodes.

Since it may be hard to understand the definition, an example is showed below:


A(1)=11+5+8=24
Details: 1->2 11
  1->4->3 5
  1->4->5 8(since 1->4 has capacity of 13)
A(2)=5+6=11
Details: 2->1->4->3 5
  2->1->4->5 6
A(3)=5
Details: 3->4->5 5
A(4)=11+5+10=26
Details: 4->1->2 11
  4->3 5
  4->5 10
A(5)=10
Details: 5->4->1->2 10

The accumulation degree of a tree is the maximal accumulation degree among its nodes. Here your task is to find the accumulation degree of the given trees.

Input

The first line of the input is an integer T which indicates the number of test cases. The first line of each test case is a positive integer n. Each of the following n - 1 lines contains three integers x, y, z separated by spaces, representing there is an edge between node x and node y, and the capacity of the edge is z. Nodes are numbered from 1 to n.
All the elements are nonnegative integers no more than 200000. You may assume that the test data are all tree metrics.

Output

For each test case, output the result on a single line.
 

Sample Input

1
5
1 2 11
1 4 13
3 4 5
4 5 10

Sample Output

26

Source


這道題的基本思想是樹形DP,如果不能理解的話請試圖把雙向邊看成兩個單向邊,再比劃比劃就出來了。
當然不一定非要以邊做為DP的單元,也可以歸到邊上(如果你有那份心的話)。
比賽的時候因為數據量大而Stack Overflow,一直想寫人工模擬棧,但因為沒寫過,在比賽中寫不出來。

五一節虛心的跟alpc62學習了怎么寫人工模擬棧,核心思想就是將同一個DFS內的不同DFS做個標記,這樣在出棧的時候就可以判斷自己所處的位置,也就知道自己該采取什么行動了。
比如
void DFS(int x) {
    for(int i = 0; i < head[x].size(); ++i) {
       DFS(head[x][i]);
    }
}
如果把(x, i)這個2元組壓入棧也就知道自己現在所處的地方了。
如果有更多的內部DFS,同樣是加對應的標記。

當然,BFS也是一種很好的選擇(應該說大多數隊伍會選擇BFS而不是人工模擬棧)

//Accumulation Degree in BFS

#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

#define Min(a, b) (a<b?a:b)
#define Max(a, b) (a>b?a:b)

struct Node
{
    int x, i, pre;
    Node() {}
    Node(int xx, int ii, int pp) {x=xx, i = ii, pre=pp;}
};

struct Edge
{
    int x, w, dp;
    Edge() {}
    Edge(int xx, int ww, int dd=0) { x=xx,w=ww,dp=dd;}
};

const int N = 200010;
vector<Edge> e[N];
bool chk[N];
int n, flow[N];

void solve() {
    int i, j, k;
    vector<Node> Q;

    fill(chk, chk + n, 0);
    fill(flow, flow + n, 0);

    for(i = 0; i < n && e[i].size()!=1; ++i);
    int st = 0, end = 0;
    chk[i] = 1;
    for(j = 0; j < e[i].size(); ++j) {
        Q.push_back(Node(i, j, -1));
        end++;
        chk[e[i][j].x] = 1;
    }
    while(st < end) {
        int x = e[Q[st].x][Q[st].i].x, pre = Q[st].pre;
        for(i = 0; i < e[x].size(); ++i) {
            if(!chk[e[x][i].x]) {
                Q.push_back(Node(x, i, st));
                end++;
                chk[e[x][i].x] = 1;
            }
        }
        ++st;
    }
    for(i = end-1; i >= 0; --i) {
        int x = Q[i].x, pre = Q[i].pre, idx = Q[i].i;
        if(e[e[x][idx].x].size() == 1) e[x][idx].dp = e[x][idx].w;
        else e[x][idx].dp = Min(e[x][idx].dp, e[x][idx].w);
        if(pre == -1) continue;
        int prex = Q[pre].x, preidx = Q[pre].i;
        e[prex][preidx].dp += e[x][idx].dp;
    }


    for(i = 0; i < e[Q[0].x].size(); ++i) {
        flow[Q[0].x] += e[Q[0].x][i].dp;
    }
    for(i = 0; i < end; ++i) {
        int x = Q[i].x, pre = Q[i].pre, idx = Q[i].i;
        int y = e[x][idx].x, xx;
        for(xx = 0; xx < e[y].size() && e[y][xx].x != x; ++xx);
        if(pre == -1) {
            e[y][xx].dp = e[y][xx].w;
        }
        else {
            e[y][xx].dp = Min(e[y][xx].dp, e[y][xx].w);
        }
        for(j = 0; j < e[y].size(); ++j) {
            flow[y] += e[y][j].dp;
        }
        for(j = 0; j < e[y].size(); ++j) {
            int yy = e[y][j].x;
            if(yy == x) continue;
            for(k = 0; k < e[yy].size() && e[yy][k].x != y; ++k);
            e[yy][k].dp = flow[y] - e[y][j].dp;
        }
    }

    int max = 0;
    for(i = 0; i < n; ++i)
        max = Max(max, flow[i]);
    printf("%d\n", max);
}

int main() {
    int ntc;
    int i;
    int x, y, w;
    scanf("%d", &ntc);
    while(ntc--) {
        scanf("%d", &n);
        for(i = 0; i < n; ++i) e[i].clear();
        for(i = 0; i < n-1; ++i) {
            scanf("%d %d %d", &x, &y, &w);
            --x; --y;
            e[x].push_back(Edge(y, w));
            e[y].push_back(Edge(x, w));
        }
        solve();
    }
    return 0;
}


Feedback

# re: 中南賽A題 Accumulation Degree  回復  更多評論   

2008-05-06 14:41 by wlzb
不錯呀,上原創精華了

# re: 中南賽A題 Accumulation Degree  回復  更多評論   

2008-05-06 18:00 by oyjpart
哦?

# re: 中南賽A題 Accumulation Degree  回復  更多評論   

2008-05-12 21:15 by alpc55
太強了,你竟然模擬棧……

# re: 中南賽A題 Accumulation Degree  回復  更多評論   

2008-05-13 22:52 by ecnu_zp
哦~~
學習學習·~

公網能進你們的oj系統嗎??

# re: 中南賽A題 Accumulation Degree  回復  更多評論   

2008-05-13 22:52 by ecnu_zp
哦~~
學習學習·~

公網能進你們的oj系統嗎??
教育網

# re: 中南賽A題 Accumulation Degree  回復  更多評論   

2008-05-13 23:50 by oyjpart
我們是軍網 外網應該不能訪問

# re: 中南賽A題 Accumulation Degree  回復  更多評論   

2008-05-14 17:15 by ecnu_zp
我還是不太明白啊~
我想的dp是N^2A的,因為要對所有點執行一次~~
我弱,能不能教我一下啊。

ecnu_zp@yahoo.cn
QQ:345717212
MSN: arena_zp@live.cn

^_^

# re: 中南賽A題 Accumulation Degree  回復  更多評論   

2008-05-14 20:08 by oyjpart
每條邊拆成2條邊 。 然后對每條邊設一個DP值。
比如邊A->B. B連接的其他點的集合叫做S(S中去掉A)
dp[A->B] = Min(Capacity[A->B], 加合(dp[B->Ci]));
可以通過2次DFS來求出這些DP值。第一次求出一個方向的邊的DP值,再一次求出反向。
試著畫個圖來理解吧:)

# re: 中南賽A題 Accumulation Degree  回復  更多評論   

2008-07-26 06:06 by lengbufang
看看!!
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产精品乱人伦中文| 亚洲男人天堂2024| 99视频在线观看一区三区| 欧美丰满高潮xxxx喷水动漫| 亚洲激情一区| 国产精品99久久久久久人| 国产精品久久午夜| 久久精品欧美| 亚洲高清一区二| 亚洲午夜未删减在线观看| 国产欧美一二三区| 久久综合影视| 9久草视频在线视频精品| 欧美在线观看一二区| 在线观看国产成人av片| 欧美日韩国产色综合一二三四| 亚洲素人在线| 欧美成人性生活| 亚洲视频狠狠| 一区二区视频在线观看| 欧美日本精品一区二区三区| 午夜在线视频一区二区区别| 欧美激情中文字幕一区二区| 亚洲永久免费| 亚洲电影在线看| 国产精品美女久久久免费| 久久精品主播| 亚洲视频观看| 亚洲国产精品成人综合| 性欧美xxxx视频在线观看| 亚洲日本乱码在线观看| 国产午夜精品一区二区三区欧美| 欧美二区在线| 久久大逼视频| 亚洲女ⅴideoshd黑人| 亚洲激情影院| 另类av导航| 午夜精品久久久久久久男人的天堂| 亚洲国产成人91精品| 国产精品一级在线| 欧美色一级片| 欧美国产免费| 久久久久91| 亚洲欧美日韩在线不卡| 99riav国产精品| 亚洲国产精品一区在线观看不卡 | 午夜久久福利| 亚洲美女免费视频| 国产亚洲一级| 国产欧美日韩91| 国产精品av免费在线观看 | 欧美精品一区二区三区在线播放 | 亚洲一区二区不卡免费| 欧美激情一区二区三区高清视频| 久久久成人精品| 欧美一区二区三区精品 | 夜夜狂射影院欧美极品| 亚洲电影自拍| 亚洲电影av| 欧美国产日韩一区二区三区| 久久久夜精品| 久久精品视频在线播放| 午夜视频在线观看一区二区三区| 国产精品99久久久久久久久久久久 | 亚洲美女在线看| 亚洲国产天堂久久综合网| 激情视频一区二区三区| 国产综合一区二区| 黄色日韩网站| 黑人极品videos精品欧美裸| 国产一区二区三区四区老人| 国产亚洲一区二区精品| 国语自产精品视频在线看8查询8| 国产视频亚洲精品| 国产丝袜一区二区| 激情成人中文字幕| 在线观看成人av| 亚洲高清一二三区| 亚洲剧情一区二区| 在线亚洲精品福利网址导航| 亚洲天堂免费观看| 小黄鸭精品aⅴ导航网站入口| 欧美一级日韩一级| 久久九九久精品国产免费直播| 久久这里有精品15一区二区三区| 麻豆九一精品爱看视频在线观看免费 | 蜜月aⅴ免费一区二区三区| 美女爽到呻吟久久久久| 欧美精品国产一区| 国产精品jvid在线观看蜜臀| 国产精品影视天天线| 国产真实乱子伦精品视频| 亚洲大胆视频| 一本久久青青| 欧美中文日韩| 欧美成人亚洲成人| 日韩午夜免费视频| 午夜视频久久久| 欧美va日韩va| 国产精品欧美精品| 精品成人一区二区三区四区| 亚洲精选成人| 欧美一区二区三区成人| 欧美**人妖| 一本色道久久综合亚洲精品按摩| 欧美亚洲视频一区二区| 免费国产自线拍一欧美视频| 欧美性感一类影片在线播放 | 欧美乱妇高清无乱码| 国产精品色午夜在线观看| 好吊色欧美一区二区三区四区| 亚洲伦理自拍| 久久国产欧美精品| 亚洲日本一区二区| 欧美一区二区三区视频免费播放| 欧美韩国日本综合| 国产午夜精品视频免费不卡69堂| 亚洲乱码久久| 久久久久久91香蕉国产| 亚洲理论在线| 久久蜜桃av一区精品变态类天堂| 欧美日韩一二三区| 亚洲国产欧美久久| 欧美一区二区三区视频免费| 亚洲欧洲美洲综合色网| 久久精品国产v日韩v亚洲 | 亚洲另类自拍| 久久综合给合| 国产视频精品va久久久久久| 亚洲视频www| 欧美国产日本韩| 欧美在线视频导航| 国产精品毛片高清在线完整版| 亚洲黄色精品| 久久久人成影片一区二区三区| 99精品欧美一区二区三区综合在线| 久久人人爽人人| 国产女主播一区| 亚洲小说区图片区| 亚洲精华国产欧美| 免费欧美日韩| 亚洲成色777777女色窝| 久久精品二区亚洲w码| 亚洲深夜激情| 欧美日韩午夜激情| 一本色道久久88精品综合| 欧美国产欧美亚洲国产日韩mv天天看完整 | aa日韩免费精品视频一| 欧美国产日本在线| 久久在线视频| 很黄很黄激情成人| 久久久久久噜噜噜久久久精品| 亚洲综合欧美日韩| 国产精品一区二区久久久久| 亚洲一区二区三区影院| 99re66热这里只有精品3直播| 欧美精品aa| 日韩视频一区二区三区在线播放| 欧美二区乱c少妇| 久久免费国产精品| 影音先锋日韩精品| 欧美aa国产视频| 美日韩精品免费| 亚洲欧洲在线免费| 亚洲人体大胆视频| 欧美久久久久中文字幕| 日韩一级在线观看| 99re6这里只有精品视频在线观看| 欧美精品一区二| 亚洲一二三区视频在线观看| 亚洲网站在线观看| 国产欧亚日韩视频| 久久精品综合网| 久久综合久色欧美综合狠狠| 91久久极品少妇xxxxⅹ软件| 亚洲精品免费在线| 国产精品高潮在线| 久久国产精品免费一区| 久久精品亚洲一区二区| 亚洲欧洲三级| 在线亚洲电影| 国产日韩欧美一区二区三区在线观看 | 亚洲人精品午夜| 亚洲免费福利视频| 国产精品久久久久久av下载红粉 | 老司机午夜精品视频在线观看| 亚洲国产裸拍裸体视频在线观看乱了中文 | 久久精品最新地址| 亚洲精品在线看| 亚洲已满18点击进入久久| 国产一区二区精品| 亚洲国产精品悠悠久久琪琪| 欧美性开放视频| 久久亚洲精品网站| 欧美精品自拍| 久久久久久亚洲综合影院红桃 | 久久嫩草精品久久久精品一| 免费看av成人| 亚洲欧美在线观看| 久久午夜av|