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

解法:深搜

 // 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. Android 用ping的方法判断当前网络是否可用

    判断网络的情况中,有个比较麻烦的情况就是连上了某个网络,但是那个网络无法上网 ,,, = = 想到了用ping指令来判断,经测试,可行~ ~ ~ private static final boolea ...

  2. 【C++深入探索】Copy-and-swap idiom详解和实现安全自我赋值

    分类: C/C++2012-08-30 21:40 2017人阅读 评论(2) 收藏 举报 任何管理某资源的类比如智能指针需要遵循一个规则(The Rule of Three): 如果你需要显式地声明 ...

  3. JDK动态代理实现原理--转载

    之前虽然会用JDK的动态代理,但是有些问题却一直没有搞明白.比如说:InvocationHandler的invoke方法是由谁来调用的,代理对象是怎么生成的,直到前几个星期才把这些问题全部搞明白了.  ...

  4. Windows Native API

    http://en.wikipedia.org/wiki/Native_API Windows 的原生 API 函数通常在系统启动时(这里其他 Windows 组件还不可用).kernel32.dll ...

  5. hdu 2544

    #include <iostream> #include <cstdio> #define INF 9999999 //#define INF 0x3f3f3f3 using ...

  6. DedeCMS批量替换栏目文件保存目录的方法

    学点sql还是很有必要的.   有时候由于栏目太多,但是要修改一下栏目的保存目录.一个一个修改真的有点费事和慢.所以想了一个方法来批量修改栏目的保存目录.就是批量替换: update dede_arc ...

  7. adb服务启动失败处理命令

    执行以下命令: D:\android-sdks\platform-tools>adb kill-server --停止adb服务 D:\android-sdks\platform-tools&g ...

  8. WordPress程序流程分析

    index.php 统一入口文件 包含wp-blog-heaer.php 包含wp-load.php 包含wp-config.php 数据库.语言包配置等 包含wp-setting.php 对各种运行 ...

  9. mobx react

    目录结构: Model/index.js 'use strict'; import { action, autorun, observable, computed } from "mobx& ...

  10. 武汉科技大学ACM:1010: 零起点学算法27——判断是否直角三角形

    Problem Description 输入三个整数,分别代表三角形的三条边长度,判断能否构成直角三角形 Input 输入3个整数a,b,c(多组数据,-5000000<a,b,c<500 ...