1.27冬休み合宿-1

5058 ワード

今日は何も勉強していません(x)、十題の練習をしましたが、英語はやはり憂鬱なものです.
練習:https://vjudge.net/contest/209626#overview
A題water、B題はみんな書いていないのに恐ろしいトラックだと思っていたが、dijkstraで、PAT甲級の1003 emergencyと類似度が極めて高く、C題は学校ojでやったことがあり、D題はKMPで、OTZ、E題water、H題STL mapを強引に勉強した.
B題を貼ってください.
B - Big Truck  
Kattis - bigtruck 
Your boss has hired you to drive a big truck, transporting items between two locations in a city. You’re given a description of the city, with locations of interest and the lengths of roads between them. Your boss requires that you take a shortest path between the starting and ending location, and she’ll check your odometer when you’re done to make sure you didn’t take any unnecessary side trips. However, your friends know you have plenty of unused space in the truck, and they have asked you to stop by several locations in town, to pick up items for them. You’re happy to do this for them. You may not be able to visit every location to pick up everything your friends want, but you’d like to pick up as many items as possible on your trip, as long as it doesn’t make the path any longer than necessary.
Figure 1: Illustrations of the first two sample inputs
The two graphs above show examples of what the city may look like, with nodes representing locations, edges representing roads and dots inside the nodes representing items your friends have asked you to pick up. Driving through a location allows you to pick up all the items there; it’s a big truck, with no limit on the items it can carry. In the graph on the left, for example, you have to drive the big truck from location $1$ to location $6$. If you follow the path $1\rightarrow 2\rightarrow 3\rightarrow 6$, the length is $9$, and you’ll get to pick up $4$ items. Of course, it would be better to drive $1\rightarrow 4\rightarrow 5\rightarrow 6$; that’s still a length of $9$, but going this way instead lets you pick up an additional item. Driving $1\rightarrow 4\rightarrow 3\rightarrow 6$ would let you pick up even more items, but it would make your trip longer, so you can’t go this way.
Input
The first line of input contains an integer, $n$ ($2\leq n\leq 100$), giving the number of locations in the city. Locations are numbered from $1$ to $n$, with location $1$ being the starting location and $n$ being the destination. The next input line gives a sequence of $n$ integers, $t_1\ldots t_ n$, where each $t_ i$ indicates the number of items your friends have asked you to pick up from location $i$. All the $t_ i$ values are between $0$ and $100$, inclusive. The next input line contains a non-negative integer, $m$, giving the number of roads in the city. Each of the following $m$ lines is a description of a road, given as three integers, $a\: b\: d$. This indicates that there is a road of length $d$ between location $a$ and location $b$. The values of $a$ and $b$ are in the range $1\ldots n$, and the value of $d$ is between $1$ and $100$, inclusive. All roads can be traversed in either direction, there is at most one road between any two locations, and no road starts and ends at the same location.
Output
If it’s not possible to travel from location $1$ to location $n$, just output out the word “impossible”. Otherwise, output the length of a shortest path from location $1$ to location $n$, followed by the maximum number of items you can pick up along the way.
Sample Input 1
Sample Output 1
6
1 1 2 3 1 0
7
1 2 2
2 3 3
3 6 4
1 4 4
4 3 2
4 5 3
5 6 2
9 5

Sample Input 2
Sample Output 2
9
1 1 1 1 1 1 1 1 1
10
1 2 3
2 5 3
1 6 2
6 7 2
7 5 2
5 3 1
3 4 2
4 9 3
5 8 2
8 9 4
12 7

Sample Input 3
Sample Output 3
2
5 5
0
impossible

题意:まずnをあげて、nの场所を表して、次の1行のnの数字は1-nの场所の点権を表して、更に1つのmをあげて、次のm行はmの辺で、1行の3つの数字はそれぞれ都市1、都市2、および都市1と都市2の距离で、无方向図なので双方向に贮蓄します.パスがあれば、最短距離と最大点権と(同じように短いと点権と大きい)を出力し、impossibleを出力します.
コードは以下の通りです(ひっそりと前に書いたemergencyのコードを変更しました)↓
#include
#include
#include
using namespace std;
const int maxv = 1010;
const int inf = 100000000000;

int mp[maxv][maxv],weight[maxv];//    mp     ,weight    
int m,n,st,ed,num[maxv],w[maxv],d[maxv];//n     ,m   ,st   ,ed   ,num       ,w      ,d     
bool vis[maxv]={false};//         

void dijkstra(int s)
{
	fill(d,d+maxv,inf);
	memset(num,0,sizeof(num));
	memset(w,0,sizeof(w));
	d[s]=0;
	w[s]=weight[s];
	num[s]=1;

	for(int i = 0;iw[v])// u           
						w[v]=w[u]+weight[v];
					num[v]+=num[u];//        
				}
			}			
		}
	}
}

int main()
{
	scanf("%d",&n);
	for(int i =0;i