eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Networking Company

Networking Company

Suppose you are a consultant for the networking company CluNet, and they have the following problem. The network that they are currently working on is modeled by a connected graph \textbf{G = (V, E)} with \textbf{N} nodes and \textbf{M} edges. Each edge e is a fiber-optic cable that is owned by one of two companies---creatively named \textbf{X} and \textbf{Y}---and leased to CluNet. Their plan is to choose a spanning tree \textbf{T} of \textbf{G} and upgrade the links corresponding to the edges of \textbf{T}. They have already concluded an agreement with companies \textbf{X} and \textbf{Y} stipulating a number of \textbf{K} so that in the tree \textbf{T} that is chosen, \textbf{K} of the edges will be owned by \textbf{X} and \textbf{N−K−1} of the edges will be owned by \textbf{Y}. CluNet management now faces the following problem. It is not at all clear to them whether there even exists a spanning tree meeting these conditions, or how to find one if it exists. So this is the problem they put to you. \InputFile The input contains a series of test cases. Each test case begins with a line containing three integers \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{1000}), \textbf{M} (\textbf{1} ≤ \textbf{M} ≤ \textbf{3000}) and \textbf{K} (\textbf{0} ≤ \textbf{K} ≤ \textbf{N−1}). The following \textbf{M} lines describe the edges. The \textbf{i}-th line contains three integers \textbf{x_i}, \textbf{y_i} and \textbf{c_i}. The \textbf{i}-th edge connects the \textbf{x_i}-th and \textbf{y_i}-th vertices. \textbf{c_i} indicates the company that owns the \textbf{i}-th edge. \textbf{c_i} is either \textbf{0} or \textbf{1}; \textbf{0} means \textbf{X} and \textbf{1} means \textbf{Y}. The input ends with a line containing three zeros. This line should not be processed. \OutputFile For each test case, output the answer as shown in the sample output. The first line of each output should indicate the test case number starting from \textbf{1}. In the next line, print "\textbf{possible}" or "\textbf{impossible}". If you can construct the spanning tree satisfying the condition, print "\textbf{possible}". Otherwise, print "\textbf{impossible}". If you can construct the spanning tree, print in the following line the numbers of the edges (beginning at \textbf{1}) that you used. Each number should be separated by a single space. You should print a blank line after each test case.
Ліміт часу 8 секунд
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
4 6 3
1 3 0
4 2 1
1 2 0
3 2 0
3 4 1
4 1 1
5 8 3
1 2 1
3 1 0
4 5 0
1 3 0
3 4 1
5 1 1
3 5 1
3 4 0
0 0 0
Вихідні дані #1
Case 1:
impossible

Case 2:
possible
1 3 4 8
Джерело Winter Camp for ACM-ICPC World Finals 2008, JAG, Practice Contest II