sicily 1024 Magic Island
题意:求无向图路径中的最大带权值.
解法:深搜
// 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的更多相关文章
- sicily1024 Magic Island(图的遍历)
Description There are N cities and N-1 roads in Magic-Island. You can go from one city to any other. ...
- Currency System in Geraldion
standard output A magic island Geraldion, where Gerald lives, has its own currency system. It uses b ...
- 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 ...
- Problem A CodeForces 560A
Description A magic island Geraldion, where Gerald lives, has its own currency system. It uses bankn ...
- 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 ...
- 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 ...
- 数据结构——Currency System in Geraldion
题目: Description A magic island Geraldion, where Gerald lives, has its own currency system. It uses b ...
- Codeforces Round #313 A Currency System in Geraldion
A Currency System in Geraldion Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64 ...
- Currency System in Geraldion (Codeforces 560A)
A Currency System in Geraldion Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64 ...
随机推荐
- 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage
POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...
- 2008年NOI全国竞赛 假面舞会
/* 分三种情况 1 有环:找环长的gcd作为max gcd的超过2的最小因子作为min 2 树:所有最长链的和作为max 3为min (最长链≥3) 3 两条相交链:找出所有的这样的两条链的差 同1 ...
- [Linux]三种方案在Windows系统下安装ubuntu双系统(转)
在学习linux的过程中,ubuntu无疑是初学者的最佳选择. 下面来列举给Windows系统安装ubuntu双系统的三种方法. 一.虚拟机安装(不推荐) 使用工具:Vmware 如果不是因为迫不得已 ...
- nyoj 76
#include <iostream> using namespace std; int main() { int i,t,n; int a[101]; cin>>t; whi ...
- requirejs和r.js的心得
requirejs的GitHub:requirejs r.js的GitHub:r.js grunt-contrib-requirejs的GitHub:grunt-contrib-requirejs r ...
- (转)安装 Apache 出现 <OS 10013> 以一种访问权限不允许的方式做了一个访问套接字的尝试
在安装Apache的过程中出现: 仔细查看提示: make_sock: could not bind to address 0.0.0.0:80 恍然大悟,计算机上安装了IIS7,80端口已占用. 打 ...
- JAVA为什么会空指针异常
1.所谓的指针,就是java中的对象的引用.比如String s;这个s就是指针. 2.所谓的空指针,就是指针的内容为空,比如上面的s,如果令它指向null,就是空指针. 3.所谓的空指针异常,就是一 ...
- solr集群solrCloud的搭建
上一章讲了solr单机版的搭建,本章将讲解sole集群的搭建.solr集群的搭建需要使用到zookeeper,搭建参见zookeeper集群的安装 一.solr实例的搭建 1. tomcat安装 这里 ...
- 动态脚本,在js里面又写js
不知道怎么回事 代码测试不过 var a=document.createElement("script"); a.type="text/javascript"; ...
- CentOS 7 之Cisco Anyconnect Secure Mobility Client
公司使用的是Cisco VPN, 于是准备使用一下.先登录公司的vpn页面,意料之中的失败,所以下载了vpnsetup.sh这个来手动安装. 手动是要用root的,不过由于我是个人学习使用机器,一直用 ...