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

解法:深搜

 // 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. Linux安装应用程序对程序文件owner/group和执行程序帐号设置的规范做法

    本文原文链接:http://blog.csdn.net/bluishglc/article/details/24384189 转载请注明出外! 本文面向的是在server环境下对已编译.自解压应用程序 ...

  2. [转] 关于SIGPIPE导致的程序退出

    PS: 如果服务器程序不忽略SIGPIPE,在某些时候TCP writer收到这个信号,会导致进程退出 The rule that applies is: When a process writes ...

  3. 基础-ADO插入数据后返回自增ID @@IDENTITY

    在文件上传中,没上传一个文件都会插入一条数据信息,那么就要返回插入的数据的id,以便进行真实删除操作.以下是ADO操作数据库的返回方法: string sql = string.Format(@&qu ...

  4. Android 面试精华题目总结

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24015867 下面的题目都是楼主在android交流群大家面试时遇到的,如果大家 ...

  5. Java基础知识强化22:Java中数据类型转换

    数据类型转换: (1). 自动转换 低级变量可以直接转换为高级变量,这叫自动类型转换.比如: byte b: int b:  long b:  float b:   double  b: 上面的语句可 ...

  6. Shell基本的命令

    ubuntu 中文乱码 如果使用的是 PuTTY,可以通过修改 font, character set 设置来解决. Window -> Appearance -> Font settin ...

  7. css07家用电器分类

    1.创建一个html页面 <!DOCTYPE html> <html> <head lang="en"> <meta charset=&q ...

  8. oracle的一知半解

    这里只讲第一次开发运用oracle数据库的.net程序遇到问题: 1.程序与oracle数据库在同一台的服务器,貌似设置好连接字符串就可以直接访问( 需要主要的问题: 字符串格式:Data Sourc ...

  9. 无法连接vCenter Server清单https://IP:10443

    VMware vCenter Server服务器安装系统的时候使用一个IP,安装完VMware vCenter后来更换了另外一个IP,当使用vSphere Web Client登陆VMware vCe ...

  10. Cacti监控Windows主机,Windows主机的正确配置

    使用cacti监控Windows主机的时候经常遇到无法获取Windows主机的snmp信息和Windows主机的硬件信息,主要原因是Windows主机没有正确配置snmp,以下是正确的配置步骤:1.安 ...