题意:求无向图路径中的最大带权值.

解法:深搜

 // Problem#: 9859
// Submission#: 2661875
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include<vector>
#include<stack>
#include<memory.h>
using namespace std; struct Road{
int From;
int Dest;
int Dist;
Road(int f,int de,int di){
From = f;
Dest = de;
Dist = di;
}
};
vector<Road> roads[];
bool visited[]; int longest;
void DSF(int k,int cur){
if(cur > longest){
longest = cur;
}
visited[k] = true;
for(int i=;i<roads[k].size();i++){
int dest = roads[k][i].Dest;
int dist = roads[k][i].Dist;
if(visited[dest])
continue;
DSF(dest,cur+dist);
}
//clear visited mark
visited[k] = false;
}
int main(){
int N,K;
while(cin>>N>>K){
int from,dest,dist;
longest = ;
memset(roads,,sizeof(roads));
memset(visited,false,sizeof(visited));
//input
for(int i=;i<N-;i++){
cin >> from >> dest >> dist;
Road rF = Road(from,dest,dist);
Road rD = Road(dest,from,dist);
roads[from].push_back(rF);
roads[dest].push_back(rD);
}
DSF(K,longest);
cout << longest <<endl;
}
return ;
}

sicily 1024 Magic Island的更多相关文章

  1. sicily1024 Magic Island(图的遍历)

    Description There are N cities and N-1 roads in Magic-Island. You can go from one city to any other. ...

  2. Currency System in Geraldion

    standard output A magic island Geraldion, where Gerald lives, has its own currency system. It uses b ...

  3. Codeforces Round #313 (Div. 2) A. Currency System in Geraldion

    A. Currency System in Geraldion Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...

  4. Problem A CodeForces 560A

    Description A magic island Geraldion, where Gerald lives, has its own currency system. It uses bankn ...

  5. Codeforces Round #313 (Div. 2) A B C 思路 枚举 数学

    A. Currency System in Geraldion time limit per test 2 seconds memory limit per test 256 megabytes in ...

  6. Codeforces Round #313 (Div. 2) A. Currency System in Geraldion 水题

    A. Currency System in Geraldion Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...

  7. 数据结构——Currency System in Geraldion

    题目: Description A magic island Geraldion, where Gerald lives, has its own currency system. It uses b ...

  8. Codeforces Round #313 A Currency System in Geraldion

    A  Currency System in Geraldion Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64 ...

  9. Currency System in Geraldion (Codeforces 560A)

    A  Currency System in Geraldion Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64 ...

随机推荐

  1. Zend Studio 10正式版破解(2013-02-26更新)

    Zend Studio 10正式版注册破解(2013-02-26完成更新) 1.以下方法仅供技术交流学习,请勿非法使用,如长期使用请支持购买正版. 2.若你还没有最新安装程序? ZendStudio ...

  2. TreeView绑定无限层级关系类

    protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind_TV(TreeView1.Nodes); ...

  3. 封装函数--->切换,添加,删除class

    var obj={}; obj.className='a b c d active'; //切换class function toggle(obj,className) { var str=obj.c ...

  4. 执行CMD命令

    可以执行多条命令,用“\r\n”分割 using System; using System.Diagnostics; namespace Tool { public class CMDHelper { ...

  5. iOS 天气应用代码中文介绍

    天气应用 解释请求参数 q: 表示Location(可以给出城市名字;或者直接给城市的经纬度) 例子:q=beijing 例子 q=48.834,2.394 num_of_days: 需要预报的天数 ...

  6. (四 )Knockout - ViewModel 的使用3 - 对象属性变化的实时更新

    ko.observableArray()就可以自动检测属性,其实他只是监控对象,而不是对象中的属性 使用ko.observable()进行处理 DEMO1 实时更新属性 //定义user数据对象 va ...

  7. oracle中存储过程详解

    oracle中存储过程的使用 过程是指用于执行特定操作的PL/SQL块.如果客户应用经常需要执行特定操作,那么可以考虑基于这些操作建立过程.通过使用过程,不仅可以简化客户应用的开发和维护,而且可以提高 ...

  8. 武汉科技大学ACM :1006: 华科版C语言程序设计教程(第二版)习题7.15

    Problem Description 输入n个字符串(n<=100),输出其中最长的串,如果有多个则取最先找到的那一个. Input 多组测试数据. 每组测试数据第一行包含一个整数n,表示一共 ...

  9. vimtutor-summary

  10. 如果设置http.get超时控制

    var timeout_wrapper = function (req) { return function () { // do some logging, cleaning, etc. depen ...