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

解法:深搜

 // 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. hdu 1685 Booksort (IDA*)

    Booksort Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others) Tot ...

  2. Asp.Net MVC 页面代码压缩筛选器-自定义删除无效内容

    Asp.Net MVC 页面代码压缩筛选器 首先定义以下筛选器,用于代码压缩. /*页面压缩 筛选器*/ public class WhiteSpaceFilter : Stream { privat ...

  3. AsyncTask两种线程池

        AsyncTask两种线程池  http://bbs.51cto.com/thread-1114378-1.html (API 3.0以后): 1.THREAD_POOL_EXECUTOR, ...

  4. 新闻源图片放到js里

    例子:http://www.s1979.com/jkys/20141209/2547965.html <script type="text/javascript" src=& ...

  5. 如何使用css、布局横向导航栏

    使用css布局横向导航栏,css应用给网页样式的方式,就相当于,给人怎么去穿上衣服,不同的衣服有不同的穿法,这里我们使用的是内联式.在这里 我们可以适当的把值调的大一点,这样我们就可以很容易的对比. ...

  6. 让sublime支持gbk常用编码

    Sublime Text 2是一个非常不错的源代码及文本编辑器,但是不支持GB2312和GBK编码在很多情况下会非常麻烦.不过Sublime Package Control所以供的插件可以让Subli ...

  7. Android应用清单文件:AndroidManifest.xml

    AndroidMainfest.xml清单文件是每个Android项目所必需的,它是整个Android应用的全家描述文件. <?xml version="1.0" encod ...

  8. 给控制器添加工具栏(Swift语言)

    //懒加载工具条 private lazy var toolBar: UIToolbar = UIToolbar() //设置底部的工具条 private func setToolBar() { // ...

  9. nodejs概论

    我将在此写下自己读<Node.js开发指南>一书的笔记,以便于以后的学习. 一.什么是node.js Node.js 是一个让 JavaScript 运行在浏览器之外的平台. Node.j ...

  10. Struts2 之 ognl

    OGNL表达式语言(#号的用法) 用法1:访问OGNL上下文和Action上下文,#相当ActionContext.getContext() 1.  如果访问其他Context中的对象,由于他们不是根 ...