题意:给出一个又向图每个图有权值和编号(正方形里的是编号),从第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. Android studio运行时报错,方法,类找不到,或者JVM内存溢出解决方案

    Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessExceptio ...

  2. Android Material Design之Toolbar与Palette

    转:http://blog.csdn.net/jdsjlzx/article/details/41441083 前言 我们都知道Marterial Design是Google推出的全新UI设计规范,如 ...

  3. sencha touch 2.3 结合cordova 环境搭建

    sencha touch 2.3环境搭建必备工具 sencha touch 2.3 包sencha cmd 4.0以上JAVA JDK 1.7以上(注意JDK和JRE的区别)Ruby 1.9.3或更早 ...

  4. lua学习笔记(1)-基本语法

    ==============变量类型nilnumber(实数)    1 2 3.14 7.65e8string            "hello world" "\n ...

  5. Android项目记录点滴

    服务器端:(根据Apache POI库函数其中SlideShow表示PPT文档,Slide表示某一张幻灯片) 1.先把电脑中的PPT文件读入到一个字节数组中.(输入流-->字节数组-->输 ...

  6. SQL Server 数据库的自动选项

    自动选项影响SQL Server 可能会自动进行的操作,所有的这些都是bool值,值为on 或off 1. auto_close: 当这个为on 时.数据库在最后一个用户退出后完全关闭,这样数据库就不 ...

  7. FastJSON应用前测试

    FastJSON 应用前测试 FastJSON是一个很好的java开源json工具类库,相比其他同类的json类库,它的速度的确是fast,最快!但是文档做得不好,在应用前不得不亲测一些功能.\ 实际 ...

  8. rootvg 镜像

    具体操作步骤如下 : a)        查看一下当前可用的硬盘: # lspv hdisk0          0002d74f0e69d97a                    rootvg ...

  9. 高效 Java Web 开发框架 JessMA v3.2.3 beta-2 发布

    JessMA(原名:Portal-Basic)是一套功能完备的高性能 Full-Stack Web 应用开发框架,内置可扩展的 MVC Web 基础架构和 DAO 数据库访问组件(内部已提供了 Hib ...

  10. Python实现Hadoop MapReduce程序

    1.概述 Hadoop Streaming提供了一个便于进行MapReduce编程的工具包,使用它可以基于一些可执行命令.脚本语言或其他编程语言来实现Mapper和 Reducer,从而充分利用Had ...