소켓과 기기 사이의 허용된 연결이 주어지고 소켓 하나를 세 배로 늘릴 수 있을 때, 동시에 전원을 공급할 수 있는 기기의 최대 개수를 구한다.
어려움8그래프동적 계획법완전 탐색DFS면접 대비아직 제출이 없습니다시간 제한2초메모리 제한512 MBAdam just moved into his new apartment and simply placed everything into it at random. This means in particular that he did not put any effort into placing his electronics in a way that each one can have its own electric socket.
Since the cables of his devices have limited reach, not every device can be plugged into every socket without moving it first. As he wants to use as many electronic devices as possible right away without moving stuff around, he now tries to figure out which device to plug into which socket. Luckily the previous owner left behind a plugbar which turns one electric socket into 3.
Can you help Adam figure out how many devices he can power in total?
The input consists of:
one line containing three integers m, n and k, where
k lines each containing two integers xi and yi indicating that socket xi can be used to power device yi.
Sockets as well as electronic devices are numbered starting from 1.
The plugbar has no cable, i.e. if it is plugged into a socket it simply triples it.
Output one line containing the total number of electrical devices Adam can power.