eolymp
bolt
Try our new interface for solving problems
Problems

Model Railroad

Model Railroad

Since childhood you have been fascinated by model railroads. Designing your own tracks, complicated intersections, train stations with miniatures of travellers, train operators, luggage is so much fun! However, it also needs a lot of space. Since your house is more than full by now, you decide to move to the garden. You have already moved all your completed tracks outside when you notice an important flaw: Since different tracks were in different rooms before, there are stations which cannot be reached from each other. That has to change! Since you have already fixed the exact positions of the stations, you know the lengths for all possible connections you can build and also which stations are connected already. All connections can be used in both directions. You can decide to remove some existing connections and instead build new ones of at most the same total length. Is it possible to rearrange the railroads so that every station is reachable from all other stations? \InputFile The first line contains three integers $n~(2 \le n \le 5 \cdot 10^4)$, $m~(0 \le m \le 2.5 \cdot 10^5)$ and $l~(0 \le l \le m)$, where $n$ is the number of stations, $m$ is the number of possible connections and $l$ is the number of connections already built; The next $m$ lines describing the connections. Each connection is described by one line with three integers $a, b~(1 \le a, b \le n)$, and $c~(0 \le c \le 5 \cdot 10^3)$ describing that there is a connection from station $a$ to station $b$ of length $c$. The first $l$ of those connections already exist. \OutputFile Output "\textbf{possible}" if it is possible to construct a connected network as described above, otherwise output "\textbf{impossible}". \Examples Figure $1$ depicts the first sample case. It is possible to connect all stations by removing the connections between stations $1$ and $2$ of length $2$ and instead building the connection between stations $2$ and $4$. The curvature of the rails does not matter because you have a hammer. \includegraphics{https://eolympusercontent.com/images/rijblhdpqp19f9en3a579fe5ak.gif} In the second case, depicted in Figure $2$, it is not possible to connect all three stations. \includegraphics{https://eolympusercontent.com/images/suctdkbenh1knce5em1mjjakds.gif}
Time limit 3 seconds
Memory limit 128 MiB
Input example #1
4 6 3
1 2 1
2 1 2
3 4 2
1 3 2
1 4 3
2 4 2
Output example #1
possible
Input example #2
3 3 2
1 2 1
1 2 2
3 2 3
Output example #2
impossible
Source 2016 German Collegiate Programming Contest (GCPC), Problem E