题意:给出一个又向图每个图有权值和编号(正方形里的是编号),从第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. OpenGL ES 三种类型 uniform attribute varying

    1.uniform变量 uniform变量是外部application程序传递给(vertex和fragment)shader的变量.因此它是application通过函数glUniform**()函 ...

  2. intial-scale=1的含义

    meta name="viewport" content="width=device-width,initial-scale=1.0" 解释  <meta ...

  3. 【Chromium中文文档】线程

    线程 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture/Threading. ...

  4. 打造坚固的安全的Linux服务器(ssh登录篇)

      Nov 3 01:22:06 server sshd[11879]: Failed password for root from 123.127.5.131 port 38917 ssh2Nov ...

  5. JavaScript初学者应知的24条最佳实践(译)

    原文:24 JavaScript Best Practices for Beginners 译者:youngsterxyf (注:阅读原文的时候没有注意发布日期,觉得不错就翻译了,翻译到JSON.pa ...

  6. Windows Azure 社区新闻综述(#68 版)

    欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻.内容和对话. 以下是过去一周基于您的反馈汇集在一起的内容: 文章.视频和博客文章 在 Windows Az ...

  7. Spring、实例化Bean的三种方法

    1.使用类构造器进行实例化 <bean id="personIService" class="cn.server.impl.PersonServiceImpl&qu ...

  8. Virtualbox 启动虚拟机报错以及扩展、显卡驱动安装

    一.Virtualbox虚拟机启动报错,如图 预先估计是BIOS中的cpu Virtualtion虚拟化支持是disable,结果一看是enable. 接下来只好Google,找到了这么一个帖子:ht ...

  9. 从Quartz时间设置问题说起

    已经好久没有来写点啥了,原因有很多,不过最主要的还是自己很懒很懒,今天终于意识到问题的严重性了.所以就来了.今天的这个问题也是前不久刚刚遇到的问题.先不啰嗦,说重点了. 一.问题描述 定时任务项目发布 ...

  10. Lua与C++的交互

    这篇文章说的挺详细的:Lua与C++的交互