题意:给出一个又向图每个图有权值和编号(正方形里的是编号),从第0号节点开始每次向当前节点所连的点中权值最大的节点移动(不会存在权值相同的节点),问最后所在的节点编号和经过的节点的权值之和。

解:模拟就好~

 #include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector> using namespace std; int T;
int n,m;
int f[];
vector <int> G[]; int main(){
scanf("%d",&T);
for (int cas=;cas<=T;cas++){
scanf("%d%d",&n,&m);
for (int i=;i<n;i++){
scanf("%d",&f[i]);
G[i].clear();
}
for (int i=;i<m;i++){
int x,y;
scanf("%d%d",&x,&y);
G[x].push_back(y);
}
int now=;
int totv=;
while (){
// printf("%d %d\n",now,totv);
int to=;
int tov=;
for (int i=;i<G[now].size();i++){
if (f[G[now][i]]>tov){
to=G[now][i];
tov=f[G[now][i]];
}
}
if (to==) break;
totv+=tov;
now=to;
}
printf("Case %d: %d %d\n",cas,totv,now);
}
return ;
}
/*
2
6 6
0 8 9 2 7 5
5 4
5 3
1 5
0 1
0 2
2 1
6 6
0 8 9 2 6 5
5 4
5 3
1 5
0 1
0 2
2 1
*/

uvalive5818 uva12376 As Long as I Learn, I Live的更多相关文章

  1. Atitit learn by need 需要的时候学与预先学习知识图谱路线图

    Atitit learn by need 需要的时候学与预先学习知识图谱路线图 1. 体系化是什么 架构 知识图谱路线图思维导图的重要性11.1. 体系就是架构21.2. 只见树木不见森林21.3. ...

  2. Python 爬取所有51VOA网站的Learn a words文本及mp3音频

    Python 爬取所有51VOA网站的Learn a words文本及mp3音频 #!/usr/bin/env python # -*- coding: utf-8 -*- #Python 爬取所有5 ...

  3. [转载]VIM 教程:Learn Vim Progressively

    文章来源:http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/   Learn Vim Progressively   TL ...

  4. some tips learn from work experience

    1.you can't avoid office politics 2.you'll never have a job which you "can't quit" - if yo ...

  5. Java-集合(没做出来)第四题 (List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列。 例如: List list = new ArrayList(); list.add(“Hello”); list.add(“World”); list.add(“Learn”); //此时list 为Hello World Learn reverseL

    没做出来 第四题 (List)写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列. 例如: List list = new ArrayList(); list.a ...

  6. Learn RxJava

    Learn RxJava http://reactivex.io/documentation/operators.html https://github.com/ReactiveX/RxJava/wi ...

  7. ANSI Common Lisp Learn

    It has been a long time that I haven't dealt with my blog. On one hand I was preparing the exams.On ...

  8. [Notes] Learn Python2.7 From Python Tutorial

    I have planed to learn Python for many times. I have started to learn Python for many times . Howeve ...

  9. 十分钟入门less(翻译自:Learn lESS in 10 Minutes(or less))

    十分钟入门less(翻译自:Learn lESS in 10 Minutes(or less)) 注:本文为翻译文章,因翻译水平有限,难免有缺漏不足之处,可查看原文. 我们知道写css代码是非常枯燥的 ...

随机推荐

  1. CSS自学笔记(8):CSS拓展(一)

    CSS元素对齐 可以使用margin属性类进行元素的水平对齐 水平对齐块元素时,可以将块元素的margin属性定义为"auto",这里需要注意的是,应该要声明!DOCTYPE,否则 ...

  2. umdh工具使用

    先安装工具,http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx 选择其中的http://msdn.microsoft.com/ ...

  3. 调用底层的viewController--返回底层

    //返回底层viewController的方法-- - (UIViewController*)GetViewController:(UIView*)uView { for (UIView* next ...

  4. spring MVC通过json与前台交互

    这里用的是spring4.1.4,jquery2.1.3,其它环境为:myeclipse2014,tomcat7,jdk7 首先,新建一个web工程,并导入springMVC的jar包(为了方便起见我 ...

  5. 量身定制顺美男女西服、衬衫、大衣、T恤等 - 北京58同城

    量身定制顺美男女西服.衬衫.大衣.T恤等 - 北京58同城 量身定制顺美男女西服.衬衫.大衣.T恤等 发布时间:2014-04-11浏览2次

  6. ruby on rails出现的问题ActiveModel::ForbiddenAttributesError

    首先分清楚我们在搞rails时.看资料和所使用的环境的版本号是否同样.看的资料是rails3.2,电脑配置的环境是4.0,就会出现这样的安全防范措施的问题. 这类问题大多出如今new或者create两 ...

  7. ubuntu 下 apache+tomcat整合_(mod-jk方法)[转]

    整合的平台是Centos5环境如下: apache源代码包: httpd-2.2.11.tar.gz  下载地址http://labs.xiaonei.com/apache-mirror/httpd/ ...

  8. 学习Java这几个快捷键你得知道(不断更新中)

    java中的System.out.println();的快捷键    --------先输入sysout  在按 alt + /

  9. easyui的样式easyui-textbox的一个bug

    easyui-testbox这个样式很恶心,用了这个就不能用传统的JQ来取值了,最近在使用上又发现了一个问题,就是赋值为0时,在输入框上会不显示,坑. <input class="ea ...

  10. unity读取Sqlite数据库

    using UnityEngine; using System.Collections; using Mono.Data.Sqlite; using System.Data; public enum ...