• <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>

            SRM 144 DIV 2 1100

            Problem Statement

                

            You work for an electric company, and the power goes out in a rather large apartment complex with a lot of irate tenants. You isolate the problem to a network of sewers underneath the complex with a step-up transformer at every junction in the maze of ducts. Before the power can be restored, every transformer must be checked for proper operation and fixed if necessary. To make things worse, the sewer ducts are arranged as a tree with the root of the tree at the entrance to the network of sewers. This means that in order to get from one transformer to the next, there will be a lot of backtracking through the long and claustrophobic ducts because there are no shortcuts between junctions. Furthermore, it's a Sunday; you only have one available technician on duty to search the sewer network for the bad transformers. Your supervisor wants to know how quickly you can get the power back on; he's so impatient that he wants the power back on the moment the technician okays the last transformer, without even waiting for the technician to exit the sewers first.

            You will be given three vector <int>'s: fromJunction , toJunction, and ductLength that represents each sewer duct. Duct i starts at junction (fromJunction[i] ) and leads to junction (toJunction[i]). ductlength[i] represents the amount of minutes it takes for the technician to traverse the duct connecting fromJunction[i] and toJunction[i]. Consider the amount of time it takes for your technician to check/repair the transformer to be instantaneous. Your technician will start at junction 0 which is the root of the sewer system. Your goal is to calculate the minimum number of minutes it will take for your technician to check all of the transformers. You will return an int that represents this minimum number of minutes.

            Definition

                
            Class: PowerOutage
            Method: estimateTimeOut
            Parameters: vector <int>, vector <int>, vector <int>
            Returns: int
            Method signature: int estimateTimeOut(vector <int> fromJunction, vector <int> toJunction, vector <int> ductLength)
            (be sure your method is public)

                題目意思:圖中有n個點,從邊(u,v)的權值是點u到點v所需的時間。現在需要遍歷圖中所有的點,問所需要的最少時間是多少。
                這類題目有一種一般的做法:設ans=2*∑cost(u,v),為所有邊的權值的和的2倍;再從起點s找一條簡單路徑path,滿足:path上的所有權值之和最大;這個可以用一個簡單的dfs輕松搞定;最后ans-path就是所需的最短時間。
            #include <iostream>
            #include 
            <vector>
            #include 
            <algorithm>
            using namespace std;

            class PowerOutage{
            public:
                
            int estimateTimeOut(vector<int> fromJunction, vector<int> toJunction, vector<int> ductLength);
                
            int dfs(int index, vector<int> fromJunction, vector<int> toJunction, vector<int> ductLength);
            }
            ;
            int PowerOutage::dfs(int index, vector<int> fromJunction, vector<int> toJunction, vector<int> ductLength){
                
            int i,ans=0,len=fromJunction.size();
                
            for(i=0;i<len;i++)
                    
            if(fromJunction[i]==index)
                        ans
            =max(ans,ductLength[i]+dfs(toJunction[i],fromJunction,toJunction,ductLength));
                
            return ans;
            }

            int PowerOutage::estimateTimeOut(vector<int> fromJunction, vector<int> toJunction, vector<int> ductLength){
                
            int i,ans=0,len=ductLength.size();
                
            for(i=0;i<len;i++)
                    ans
            +=2*ductLength[i];
                ans
            -=dfs(0,fromJunction,toJunction,ductLength);
                
            return ans;
            }

            posted on 2009-05-23 14:42 極限定律 閱讀(599) 評論(0)  編輯 收藏 引用 所屬分類: TopCoder

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導航

            統計

            常用鏈接

            留言簿(10)

            隨筆分類

            隨筆檔案

            友情鏈接

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            精品久久久久久无码专区| 久久精品国产亚洲av高清漫画| 久久久久亚洲精品无码蜜桃 | 国内精品久久久久影院薰衣草| 精品熟女少妇aⅴ免费久久| 久久综合给合综合久久| 99精品久久久久久久婷婷| 午夜精品久久久久久毛片| 久久国产乱子伦精品免费午夜| 亚洲精品无码久久久久去q | 久久午夜伦鲁片免费无码| 国产精品成人99久久久久 | 久久天堂AV综合合色蜜桃网| 国产精品久久久天天影视| 久久天天躁狠狠躁夜夜不卡| AA级片免费看视频久久| 伊人久久成人成综合网222| 国内精品久久久久久久久| 国产成人无码精品久久久性色| 久久综合综合久久狠狠狠97色88| 亚洲午夜无码久久久久| 狠狠色伊人久久精品综合网| 亚洲综合伊人久久大杳蕉| 久久天天躁狠狠躁夜夜96流白浆 | 2021精品国产综合久久| 亚洲人成无码www久久久| 国产亚洲美女精品久久久| 国产精品久久久福利| 亚洲中文久久精品无码ww16 | 欧美一区二区精品久久| 久久亚洲AV成人无码电影| 国产精品中文久久久久久久| 日日狠狠久久偷偷色综合免费 | 久久婷婷色香五月综合激情| 久久婷婷午色综合夜啪| 久久精品?ⅴ无码中文字幕| 嫩草影院久久99| 久久综合久久综合久久综合| 青青青青久久精品国产| 国产精品青草久久久久婷婷| 东京热TOKYO综合久久精品|