eolymp
bolt
Try our new interface for solving problems
Məsələlər

Networking Company

Networking Company

Zaman məhdudiyyəti 8 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB

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.

Giriş verilənləri

The input contains a series of test cases.

Each test case begins with a line containing three integers N (1N1000), M (1M3000) and K (0KN−1).

The following M lines describe the edges. The i-th line contains three integers x_i, y_i and c_i. The i-th edge connects the x_i-th and y_i-th vertices. c_i indicates the company that owns the i-th edge. c_i 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.

Çıxış verilənləri

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.

Nümunə

Giriş verilənləri #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
Çıxış verilənləri #1
Case 1:
impossible

Case 2:
possible
1 3 4 8
Mənbə Winter Camp for ACM-ICPC World Finals 2008, JAG, Practice Contest II