VK Cup 2017
来源:互联网 发布:spd7网络信号避雷器 编辑:程序博客网 时间:2024/04/27 00:31
In the country of Never, there are n cities and a well-developed road system. There is exactly one bidirectional road between every pair of cities, thus, there are as many as roads! No two roads intersect, and no road passes through intermediate cities. The art of building tunnels and bridges has been mastered by Neverians.
An independent committee has evaluated each road of Never with a positive integer called the perishability of the road. The lower the road's perishability is, the more pleasant it is to drive through this road.
It's the year of transport in Never. It has been decided to build a museum of transport in one of the cities, and to set a single signpost directing to some city (not necessarily the one with the museum) in each of the other cities. The signposts must satisfy the following important condition: if any Neverian living in a city without the museum starts travelling from that city following the directions of the signposts, then this person will eventually arrive in the city with the museum.
Neverians are incredibly positive-minded. If a Neverian travels by a route consisting of several roads, he considers the perishability of the route to be equal to the smallest perishability of all the roads in this route.
The government of Never has not yet decided where to build the museum, so they consider all n possible options. The most important is the sum of perishabilities of the routes to the museum city from all the other cities of Never, if the travelers strictly follow the directions of the signposts. The government of Never cares about their citizens, so they want to set the signposts in a way which minimizes this sum. Help them determine the minimum possible sum for all n possible options of the city where the museum can be built.
The first line contains a single integer n (2 ≤ n ≤ 2000) — the number of cities in Never.
The following n - 1 lines contain the description of the road network. The i-th of these lines contains n - i integers. The j-th integer in thei-th line denotes the perishability of the road between cities i and i + j.
All road perishabilities are between 1 and 109, inclusive.
For each city in order from 1 to n, output the minimum possible sum of perishabilities of the routes to this city from all the other cities of Never if the signposts are set in a way which minimizes this sum.
31 23
223
62 9 9 6 67 1 9 109 2 54 108
6575711
The first example is explained by the picture below. From left to right, there is the initial road network and the optimal directions of the signposts in case the museum is built in city 1, 2 and 3, respectively. The museum city is represented by a blue circle, the directions of the signposts are represented by green arrows.
For instance, if the museum is built in city 3, then the signpost in city 1 must be directed to city 3, while the signpost in city 2 must be directed to city 1. Then the route from city 1 to city 3 will have perishability 2, while the route from city 2 to city 3 will have perishability 1. The sum of perishabilities of these routes is 3.
#include <bits/stdc++.h>#define N 2005#define MOD 1000000007#define INF 114748364700000llusing namespace std;typedef long long ll;int n;ll Min,g[N][N],f[N];bool vis[N];int main(){ memset(f,0x3f,sizeof(f)); Min = INF; scanf("%d",&n); for(int i = 1;i <= n;i++) for(int j = i+1;j <= n;j++) { scanf("%I64d",&g[i][j]); g[j][i] = g[i][j]; if(Min > g[i][j]) Min = g[i][j]; } for(int i = 1;i <= n;i++) for(int j = 1;j <= n;j++) if(i != j) { g[i][j] -= Min; f[i] = min(f[i],2*g[i][j]); } for(int i = 1;i <= n;i++) { int t = 0; for(int j = 1;j <= n;j++) if(f[t] > f[j] && !vis[j]) t = j; vis[t] = 1; for(int j = 1;j <= n;j++) f[j] = min(f[j],f[t] + g[t][j]); } for(int i = 1;i <= n;i++) cout<<f[i]+(n-1ll)*Min<<endl;}
- VK Cup 2017
- Codeforces VK Cup 2017
- VK Cup 2017
- VK Cup 2017
- VK Cup 2017
- VK Cup 2017
- [杂题] Codeforces 772D VK Cup 2017
- [几何] Codeforces 772B VK Cup 2017
- VK CUP 2017 C String Reconstruction
- 【VK Cup 2012】final
- Codeforences #351 VK CUP
- VK Cup 2015
- Codeforces VK Cup 2015
- [Codeforces VK Cup 2016
- VK Cup 2015
- VK Cup 2015
- [数论 DAG最长路] Codeforces 772C VK Cup 2017
- [交互 点分治] Codeforces 772E VK Cup 2017
- 最短路(Dijkstra)
- Mysql同步问题
- HTTP协议和socket协议的差别及使用
- bzoj1534: [POI2005]Sum- Fibonacci sums
- Cannot return from outside a function or method
- VK Cup 2017
- 《Orange'S:一个操作系统的实现》学习笔记(1)
- 关于java 客户端链接不上redis的解决方案
- 数据结构-树的学习 (1)
- JAVA IO流总结(一)——字符流
- 商店购物 Shopping Offers(完全背包问题+结构体使用)
- Java Web从零开始
- 一心想去今日头条,看看现在的招聘,警醒自己,每天不能太放纵,要想提高就得不断学习,拼命努力
- strtok()函数和getopt()函数