Problem 3047 --Andy and Maze

3047: Andy and Maze

"
Time Limit $15$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $5$ 正确数量 $0$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
Andy is a famous explorer at Nanjing University second to none. One day he was trapped in a maze. The maze consisted of several rooms, and there was a precious gem in each room. There were also some bidirectional roads connecting some pairs of these rooms. It took some time to travel along the road in either direction. 

Andy was in a room, but he didn't know which room he was in. Suddenly, he heard a low voice, saying that, "if you want to get out of the maze, you must collect kk gems." Andy wanted to know, what was the maximum possible time to get out of the maze, or it was impossible at all? Note that he couldn't visit the same room more than once. 
The first line of input consists of a single integer TT (1≤T≤35)(1≤T≤35), denoting the number of test cases. Each test case starts with a line of three integers n,m,kn,m,k (2≤n≤104,1≤m≤104,2≤k≤6)(2≤n≤104,1≤m≤104,2≤k≤6), denoting the number of rooms and the number of roads in the maze, and the number of gems he needed to collect, respectively. Each of the next mm lines contains three intergers u,v,tu,v,t (1≤u,v≤n,u≠v,1≤t≤108)(1≤u,v≤n,u≠v,1≤t≤108), specifying a road connecting the uuth and the vvth rooms, which took tt minutes to travel in either direction. No two roads connected the same pair of rooms. 
There are at most 5 test cases with max{n,m}>100max{n,m}>100.
For each test case, print the maximum possible time in minute to get out of the maze in one line. If it was impossible to get out of the maze, print impossibleimpossible instead.
2
4 4 3
1 2 6
2 3 1
2 4 4
1 4 5
5 3 4
1 2 2
2 3 3
4 5 5
11
impossible

推荐代码 查看3047 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$ $ms]
内存最少[$ $KB]
第一AC
第一挑战 淡意的温柔 591133 2020-06-06 08:34:00

赛题来源/所属竞赛 2019 Multi-University Training Contest 8 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛