Big Bed

시간 제한1초메모리 제한1024 MB

요약
포털들의 크기와 연결 관계가 주어질 때, 상점에서 방까지 가는 어떤 경로의 모든 포털을 통과할 수 있는 직육면체 상자의 최대 크기를 구한다.
난이도

보통10점 중 7점

유형
그래프, BFS, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Somewhere in the galaxy far, far away, on the planet Nibiru, Basilius, one of the most promising students, has received a special scholarship in the prestigious Nibirian State University (NSU). He's decided to buy a bed for his dorm room.

He wants a bed with the maximum possible volume, but, on the other hand, the size of his future bed is limited --- Basilius wants to save some space in his room for his future shopping trophies.

Any bed can be crafted in the local store, provided it's a rectangular parallelepiped. But not any bed can be delivered from the store to the dorm room. It will have to be carried through portals, which resemble our common rectangular doors. The portals are perpendicular to the floor. Passing through a portal brings you either to the vicinity of some other portals or to a room. Help Basilius calculate the optimal bed size for his room. The distance between portals is significantly greater than the size of the dorm room.

It's assumed that the bed is oriented so that a fixed face will always be parallel to the floor and another fixed face will be parallel to the plane containing current portal.

The bed will not be rotated once it's lifted to be carried through portals to the room.

입력

The first line of the input file contains three integers aa, bb and cc limiting the bed dimensions. One of the dimensions (length, width, and height) must not exceed aa, another dimension must not exceed bb, and the remaining dimension does not exceed cc (1≤a,b,c≤5001 \le a, b, c \le 500).

The next line contains a single integer nn -- the number of portals on the planet (2≤n≤5002 \leq n \le 500). The portals are numbered from 11 to nn. The portal in the shop has number 11, and the portal leading to Basilius' room has number nn.

The next nn lines of the input file describe the Nibiru portals, one per line. ii-th of these lines contains a description of the ii-th portal and begins with three real numbers separated by spaces -- w_iw\_i, h_ih\_i and k_ik\_i, the first two defining the width and height of the portal and the third one denoting the number of portals which can be reached directly by passing through the described portal (1≤w_i,h_i≤3001 \leq w\_i, h\_i \leq 300,0≤k_i<n0 \le k\_i < n). Then k_ik\_i pairwise distinct integers p_ijp\_{ij} follow: they describe numbers of portals directly accessible from the ii-th portal (1≤p_ij≤n1 \le p\_{ij} \le n, p_ij≠ip\_{ij} \neq i).

출력

The output file must contain three positive integers xx, yy, zz in any order --- the dimensions of the bed with the maximum possible volume that Basilius can bring to his dorm room from the store. If there are several possible variants with the largest volume, print any of them. It is guaranteed that there exists a solution to the problem.

예제2

  1. 예제 1

    입력
    300 300 300
    4
    300 300 1 2
    100 200 1 4
    300 200 1 1
    300 300 2 3 1
    
    예상 출력
    100 200 300
    
  2. 예제 2

    입력
    300 300 300
    4
    300 300 2 2 3
    100 200 1 4
    300 200 1 4
    300 300 1 1
    
    예상 출력
    200 300 300