Raging River
시간 제한2초메모리 제한1024 MB
두 강둑과 통나무 간선으로 이루어진 작은 그래프에서 P명이 순서대로 건너되 지나간 간선은 사라진다고 할 때, 최대한 많은 사람을 건너보내고 총 이동 시간을 최소화한다.
문제
Sally and her friends are trying to cross safely from one bank of a raging river to another. Boulders are scattered within the river, with log planks connecting the banks of the river to some of the boulders, and some pairs of boulders to each other.
Sally begins by trying to cross the river first. She starts at the left bank and crosses one plank at a time, with the goal of reaching the right bank. Walking across a plank takes Sally one second. Each time she crosses a plank, that plank becomes unstable and collapses into the river (so that neither Sally nor her friends can use that plank again). After Sally has safely reached the right bank, another friend tries to cross the river, and so on, until everyone who is able to make it has crossed the river.
Given the graph of banks/boulders and planks and the number of people who need the cross the river, what is the smallest amount of total time (in seconds) required for everyone to cross the river safely? If it is impossible for all people to cross, compute the minimum number of people who must be left behind and print n people left behind.
입력
The first line of the input contains three integers , , and : the number of people who must cross the river, the number of boulders in the river, and the number of logs spanning boulders/river banks. These integers satisfy and and .
Then follows lines, each of which contains two integers and specifying the endpoints on one log. The values for and are in the range , where signifies the left river bank, signifies the right river bank, and all other values indicate one of the boulders in the river.
You may assume that every log has two distinct endpoints, and that no two logs span the same pair of boulders/river banks. There is no guarantee that every boulder, or even the right river bank, is reachable from the left river bank.
출력
If it is possible for all people to reach the right bank, print a single integer, the minimum total time (in seconds) required for all people to cross.
If some people must be left behind at the left bank, instead print n people left behind, where the integer is the least number of people who must be left behind.