2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路
transaction transaction transaction
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 1496 Accepted Submission(s): 723
As we know, the price of this book was different in each city. It is ai yuan in it city. Kelukin will take taxi, whose price is 1yuan per km and this fare cannot be ignored.
There are n−1 roads connecting n cities. Kelukin can choose any city to start his travel. He want to know the maximum money he can get.
For each test case:
first line contains an integer n (2≤n≤100000) means the number of cities;
second line contains n numbers, the ith number means the prices in ith city; (1≤Price≤10000)
then follows n−1 lines, each contains three numbers x, y and z which means there exists a road between x and y, the distance is zkm (1≤z≤1000).
4
10 40 15 30
1 2 30
1 3 2
3 4 10
- #include<bits/stdc++.h>
- //#include<regex>
- #define db double
- #define ll long long
- #define vec vector<ll>
- #define Mt vector<vec>
- #define ci(x) scanf("%d",&x)
- #define cd(x) scanf("%lf",&x)
- #define cl(x) scanf("%lld",&x)
- #define pi(x) printf("%d\n",x)
- #define pd(x) printf("%f\n",x)
- #define pl(x) printf("%lld\n",x)
- #define MP make_pair
- #define PB push_back
- #define fr(i,a,b) for(int i=a;i<=b;i++)
- using namespace std;
- const int N=1e6+;
- const int mod=1e9+;
- const int MOD=mod-;
- const db eps=1e-;
- const db pi = acos(-1.0);
- const int inf = 0x3f3f3f3f;
- const ll INF = 0x3f3f3f3f3f3f3f3f;
- int a[N],d[N],vis[N];
- struct P
- {
- int u,v,w;
- P(int x,int y,int z):u(x),v(y),w(z){};
- P(){};
- };
- vector<P> g[N],e;
- queue<int> q;
- void add(int x,int y,int z)
- {
- g[x].push_back(P(x,y,z));
- }
- void spfa(int n)
- {
- memset(d,, sizeof(d));
- memset(vis,, sizeof(vis));
- vis[]=;
- q.push();
- while(q.size())
- {
- int u=q.front();q.pop();
- vis[u]=;
- for(int i=;i<g[u].size();i++){
- int v=g[u][i].v;
- int w=g[u][i].w;
- if(d[v]<d[u]+w){// get the maxmum
- d[v]=d[u]+w;
- if(!vis[v]){
- vis[v]=;//push the new point
- q.push(v);
- }
- }
- }
- }
- pi(d[n+]);
- }
- int main()
- {
- int t;
- ci(t);
- while(t--)
- {
- int n;
- ci(n);
- for(int i=;i<=n;i++) g[i].clear();
- for(int i=;i<=n;i++)
- ci(a[i]),add(,i,a[i]),add(i,n+,-a[i]);
- for(int i=;i<n;i++){
- int x,y,z;
- ci(x),ci(y),ci(z);
- add(x,y,-z);
- add(y,x,-z);
- }
- spfa(n);
- }
- }
2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路的更多相关文章
- hdu6201 transaction transaction transaction(from 2017 ACM/ICPC Asia Regional Shenyang Online)
最开始一直想着最短路,不过看完题解后,才知道可以做成最长路.唉,还是太菜了. 先上图: 只要自己添加两个点,然后如此图般求最长路即可,emmm,用SPFA可以,迪杰斯特拉也可以,或者别的都ok,只要通 ...
- 2017 ACM/ICPC Asia Regional Shenyang Online(部分题解)
HDU 6197 array array array 题意 输入n和k,表示输入n个整数和可以擦除的次数k,如果至多擦除k次能是的数组中的序列是不上升或者是不下降序列,就是魔力数组,否则不是. 解题思 ...
- HDU 6205(尺取法)2017 ACM/ICPC Asia Regional Shenyang Online
题目链接 emmmm...思路是群里群巨聊天讲这题是用尺取法.....emmm然后就没难度了,不过时间上3000多,有点.....盗了个低配本的读入挂发现就降到2800左右, 翻了下,发现神犇Clar ...
- HDU 6198(2017 ACM/ICPC Asia Regional Shenyang Online)
思路:找规律发现这个数是斐波那契第2*k+3项-1,数据较大矩阵快速幂搞定. 快速幂入门第一题QAQ #include <stdio.h> #include <stdlib.h& ...
- 2017 ACM/ICPC Asia Regional Shenyang Online array array array
2017-09-15 21:05:41 writer:pprp 给出一个序列问能否去掉k的数之后使得整个序列不是递增也不是递减的 先求出LIS,然后倒序求出最长递减子序列长度,然后判断去k的数后长度是 ...
- 2017 ACM/ICPC Asia Regional Shenyang Online card card card
题意:看后面也应该知道是什么意思了 解法: 我们设置l,r,符合条件就是l=起始点,r=当前点,不符合l=i+1 学习了一下FASTIO #include <iostream> #incl ...
- 2017 ACM/ICPC Asia Regional Shenyang Online transaction transaction transaction
Problem Description Kelukin is a businessman. Every day, he travels around cities to do some busines ...
- 2017 ACM/ICPC Asia Regional Shenyang Online number number number
题意:求n个斐波那契数列组合都无法得到的最小数字 解法: 1 我们先暴力的求出前面几个数字 2 然后再暴力的求递推 3 接着矩阵快速幂(没写错吧?) /*#include<bits/stdc++ ...
- 2017 ACM/ICPC Asia Regional Shenyang Online cable cable cable
Problem Description Connecting the display screen and signal sources which produce different color s ...
随机推荐
- ios播放音乐
1.背景音乐播放 循环播放长音乐 支持mp3格式 #import <AVFoundation/AVFoundation.h>: NSString *musicFilePath = ...
- bitset基础用法+心得
今天上午听AntiLeaf学长讲课,获悉了bitset这种神奇的操作,还是大喊一句:stl大法吼啊! bitset是用来进行一些状态储存的操作.类似于一个标记数组,又类似于状压里面的二进制. 它与状压 ...
- python 深浅拷贝
先定义一个列表 >>> s = [1,'alex','alvin'] >>> s2 = s.copy() 使用copy()方法拷贝,创建一个新的对象s2 >& ...
- 【性能测试工具】- ApacheBench
优点:提供的测试结果信息更完备:缺点:每次只能测试一个链接 概述: ab全称是ApacheBench,是 Apache 附带的一个HTTP性能测试小工具,可以同时模拟多个并发请求. 安装: Apach ...
- CSS格式与布局中三种位置的理解与应用
第一种位置关系:position:fixed 锁定位置(相对于整个浏览器的位置),常用在各大网站的右下角或其它位置的小广告. 如果需要调整锁定位置,需要使用如下方式:<div style=&q ...
- .Net之用户控件笔记
前端初始化: 记录点:不需要写jquery的onload,只需要在<script></script>里面直接调用 <script type="text/java ...
- css复习内容
有时候 自己动手写一遍比想十遍都有用 <!DOCTYPE html><html> <head> <meta charset="utf-8" ...
- Linux学习总结(七)—— CentOS软件包管理:脚本安装
脚本安装就是软件编写者写好一个shell脚本或者java脚本,你只需要输入一些简单的信息便可直接安装.这种安装方式方便简单,类似于Windows下软件的安装方式. 下面以webmin的安装为例讲解脚本 ...
- 分页(将数据库中的多条数据一页一页的显示在jsp页面中)
一.显示数据库中的多条数据为什么要用分页 在真正的开发中,数据库中所存储的数据绝对不像我们平时所写的那样,仅仅有几条数据,而是有几十条甚至上百条,像淘宝京东的用户把都是上几十万甚至百万的.如果这时候在 ...
- ffmpeg音频播放代码示例-avcodec_decode_audio4
一.概述 最近在学习ffmpeg解码的内容,参考了官方的教程http://dranger.com/ffmpeg/tutorial03.html,结果发现这个音频解码的教程有点问题.参考了各种博客,并同 ...