아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Networking Company

시간 제한8초메모리 제한512 MB

요약
연결 그래프에서 X 종류 간선을 정확히 K개 포함하는 신장 트리가 존재하는지 판별하고, 존재하면 사용한 간선 번호를 출력한다.
난이도

보통10점 중 6점

유형
그래프, 최소 신장 트리, 유니온 파인드, 그리디
정답자
아직 제출이 없습니다

문제

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 G = (V, E) with N nodes and M edges. Each edge e is a fiber-optic cable that is owned by one of two companies—creatively named X and Y—and leased to CluNet. Their plan is to choose a spanning tree T of G and upgrade the links corresponding to the edges of T. They have already concluded an agreement with companies X and Y stipulating a number of K so that in the tree T that is chosen, K of the edges will be owned by X and N − K − 1 of the edges will be owned by 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.

입력

The input contains a series of test cases.

Each test case begins with a line containing three integers N (1 ≤ N ≤ 1000), M (1 ≤ M ≤ 3000) and K (0 ≤ K ≤ N − 1).

The following M lines describe the edges. The i-th line contains three integers xi, yi and ci. The i-th edge connects the xi-th and yi-th vertices. ci indicates the company that owns the i-th edge. ci is either 0 or 1; 0 means X and 1 means Y.

The input ends with a line containing three zeros. This line should not be processed.

출력

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 1.

In the next line, print “possible” or “impossible”. If you can construct the spanning tree satisfying the condition, print “possible”. Otherwise, print “impossible”.

If you can construct the spanning tree, print in the following line the numbers of the edges (beginning at 1) that you used. Each number should be separated by a single space.

You should print a blank line after each test case.

예제1

  1. 예제 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
    
    예상 출력
    Case 1:
    impossible
    
    Case 2:
    possible
    1 3 4 8