B - ROADS
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
N cities named with numbers 1 ... N are connected with one-way roads. Each road has two parameters associated with it : the road length and the toll that needs to be paid for the road (expressed in the number of coins).
Bob and Alice used to live in the city 1. After noticing that Alice was cheating in the card game they liked to play, Bob broke up with her and decided to move away - to the city N. He wants to get there as quickly as possible, but he is short on cash.
We want to help Bob to find
the shortest path from the city 1 to the city N
that he can afford with the amount of money he has.
Output
The first and the only line of the output should contain the total length of the shortest path from the city 1 to the city N whose total toll is less than or equal K coins.
If such path does not exist, only number -1 should be written to the output.
题意:求征税k内从1到n的最短路。
思路:这题我真不想说了,做了整整一天啦!我承认自己太笨了,只能默默努力了。WA了好多发,然后发现错误后,又T了好多发,改进了好多次,到最后用multimap才水过……唉……
第一种做法:multimap用时250ms
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
第二种做法:邻接表,用时32ms
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include