eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Power Network

Power Network

\includegraphics{https://static.e-olymp.com/content/e7/e74d54278784e28fb95028ce0b789b99745a4d4f.jpg} A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node \textbf{u} may be supplied with an amount \textbf{s(u)} ≥ \textbf{0} of power, may produce an amount \textbf{0} ≤ \textbf{p(u)} ≤ \textbf{p_max(u)} of power, may consume an amount \textbf{0} ≤ \textbf{c(u)} ≤ \textbf{min(s(u),c_max(u))} of power, and may deliver an amount \textbf{d(u)=s(u)+p(u)-c(u)} of power. The following restrictions apply: \textbf{c(u)=0} for any power station, \textbf{p(u)=0} for any consumer, and \textbf{p(u)=c(u)=0} for any dispatcher. There is at most one power transport line \textbf{(u,v)} from a node \textbf{u} to a node \textbf{v} in the net; it transports an amount \textbf{0} ≤ \textbf{l(u,v)} ≤ \textbf{l_max(u,v)} of power delivered by \textbf{u} to \textbf{v}. Let \textbf{Con = _u(cu)} be the power consumed in the net. The problem is to compute the maximum value of \textbf{Con}. \includegraphics{https://static.e-olymp.com/content/79/790424c7eca70603ba6c655f90dc151603b1fa29.jpg} An example is in figure. The label \textbf{x/y} of power station \textbf{u} shows that \textbf{p(u)=x} and \textbf{p_max(u)=y}. The label \textbf{x/y} of consumer \textbf{u} shows that \textbf{c(u)=x} and \textbf{c_max(u)=y}. The label \textbf{x/y} of power transport line \textbf{(u,v)} shows that \textbf{l(u,v)=x} and \textbf{l_max(u,v)=y}. The power consumed is \textbf{Con=6}. Notice that there are other possible states of the network but the value of \textbf{Con} cannot exceed \textbf{6}. \InputFile There are several data sets in the input text file. Each data set encodes a power network. It starts with four integers: \textbf{0} ≤ \textbf{n} ≤ \textbf{100} (nodes), \textbf{0} ≤ \textbf{n_p} ≤ \textbf{n} (power stations), \textbf{0} ≤ \textbf{n_c} ≤ \textbf{n} (consumers), and \textbf{0} ≤ \textbf{m} ≤ \textbf{n^2} (power transport lines). Follow \textbf{m} data triplets \textbf{(u,v)z}, where \textbf{u} and \textbf{v} are node identifiers (starting from \textbf{0}) and \textbf{0} ≤ \textbf{z} ≤ \textbf{1000} is the value of \textbf{l_max(u,v)}. Follow \textbf{n_p} doublets \textbf{(u)z}, where \textbf{u} is the identifier of a power station and \textbf{0} ≤ \textbf{z} ≤ \textbf{10000} is the value of \textbf{p_max(u)}. The data set ends with \textbf{n_c} doublets \textbf{(u)z}, where \textbf{u} is the identifier of a consumer and \textbf{0} ≤ \textbf{z} ≤ \textbf{10000} is the value of \textbf{c_max(u)}. All input numbers are integers. Except the \textbf{(u,v)z} triplets and the \textbf{(u)z} doublets, which do not contain white spaces, white spaces can occur freely in input. Input data terminate with an end of file and are correct. \OutputFile For each data set from the input, the program prints on the standard output the maximum amount of power that can be consumed in the corresponding network. Each result has an integral value and is printed from the beginning of a separate line.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20
7 2 3 13 (0,0)1 (0,1)2 (0,2)5 (1,0)1 (1,2)8 (2,3)1 (2,4)7 (3,5)2 (3,6)5 (4,2)7 (4,3)5 (4,5)1 (6,0)5 (0)5 (1)2 (3)2 (4)1 (5)4
Выходные данные #1
15
6
Источник ACM ICPC Southeastern European Regional Programming Contest, Bucharest, Romania, October 18, 2003