F. Flow of Orz Pandas

Codeforces
IDCF10287F
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
There are $n$ villages in a county of the Orz Pandas. The $i$-th village needs $w_i$ tons of water per day. The Orz Pandas have built $k$ water supply facilities. The $i$-th water supply facility is located at the $s_i$-th village. The water supply facilities are very powerful, so we could consider each of them able to supply infinite amount of water per day. The Orz Pandas have built water supply pipe networks to satisify the water usage of the villages. There are $m$ water supply pipes already built. The $i$-th pipe is between the village $u_i$ and the village $v_i$. The pipes are bidirectional: if there is a pipe between $u_i$ and $v_i$, it's allowed to transfer water from $u_i$ to $v_i$, or from $v_i$ to $u_i$, through this pipe. Pipe $i$ has a parameter $c_i$. If $f_i$ tons of water are transfered through the $i$-th pipe per day, the Orz Pandas will have to pay $f_i^2 times c_i$ dollars per day to maintain the pipe. Please tell the Orz Pandas the minimum cost they must pay per day, to satisify the water usage of all the villages. There is only one test case in each input file. It's guaranteed that $1 <= n <= 50$, $0 <= m <= 200$, $1 <= k, s_i, u_i, v_i <= n$, and $0 <= w_i, c_i <= 1000$. There *may* be multiple pipes connecting the same pair of villages. There *may* be some pipe both endings of which are the same village. There *may* be multiple water supply facilities in the same village. If the water usage of all the villages can be satisified, output one line containing a decimal, which is the minimum cost. Otherwise, output one line containing $-1$. Your answer will be considered correct if its absolute or relative error does not exceed $10^(-9)$. For the first sample, the optimal solution is: For the second sample, it's impossible to satisify village $7$ since there is no way to connect it to a water supply facility. ## Input There is only one test case in each input file. The first line contains three integers $n$, $m$, and $k$. The second line contains $n$ integers $w_1, w_2, \\\\cdots, w_n$. The third line contains $k$ integers $s_1, s_2, \\\\cdots, s_k$. The $i$-th of the following $m$ lines contains three integers $u_i$, $v_i$, and $c_i$. It's guaranteed that $1 <= n <= 50$, $0 <= m <= 200$, $1 <= k, s_i, u_i, v_i <= n$, and $0 <= w_i, c_i <= 1000$.There *may* be multiple pipes connecting the same pair of villages. There *may* be some pipe both endings of which are the same village. There *may* be multiple water supply facilities in the same village. ## Output If the water usage of all the villages can be satisified, output one line containing a decimal, which is the minimum cost. Otherwise, output one line containing $-1$. Your answer will be considered correct if its absolute or relative error does not exceed $10^(-9)$. [samples] ## Note For the first sample, the optimal solution is: Transfer $1. 25$ tons of water from village $1$ to village $2$ per day, costing $1. 25^2 times 1 = 1. 5625$ dollars per day. Transfer $0. 75$ tons of water from village $3$ to village $4$ per day, costing $0. 75^2 times 2 = 1. 125$ dollars per day. Transfer $0. 25$ tons of water from village $2$ to village $4$ per day, costing $0. 25^2 times 1 = 0. 0625$ dollars per day. Transfer $1$ ton of water from village $2$ to village $5$ per day, costing $1^2 times 2 = 2$ dollars per day. Transfer $1$ ton of water from village $4$ to village $6$ per day, costing $1^2 times 1 = 1$ dollars per day. For the second sample, it's impossible to satisify village $7$ since there is no way to connect it to a water supply facility.
**Definitions** Let $ n \in \mathbb{Z} $ be the number of data points. Let $ P_i = (x_i, y_i, z_i) \in \mathbb{R}^3 $, $ i \in \{1, \dots, n\} $, be the coordinates of the data points. Let $ c_i \in \{1, 2\} $ be the class label of point $ P_i $. Let $ \mathcal{P}_1 = \{ P_i \mid c_i = 1 \} $, $ \mathcal{P}_2 = \{ P_i \mid c_i = 2 \} $ be the two classes. **Constraints** 1. $ 2 \leq n \leq 500 $ 2. $ |x_i|, |y_i|, |z_i| \leq 1000 $ 3. All $ P_i $ are distinct. 4. $ \mathcal{P}_1 \neq \emptyset $, $ \mathcal{P}_2 \neq \emptyset $ **Objective** Determine if there exists a hyperplane $ \mathcal{H}: \mathbf{w} \cdot \mathbf{x} + b = 0 $, with $ \mathbf{w} \in \mathbb{R}^3 \setminus \{\mathbf{0}\} $, $ b \in \mathbb{R} $, such that: - $ \mathbf{w} \cdot P_i + b > 0 $ for all $ P_i \in \mathcal{P}_1 $, - $ \mathbf{w} \cdot P_i + b < 0 $ for all $ P_i \in \mathcal{P}_2 $. If such a hyperplane exists, compute the **margin**: $$ \text{margin} = \frac{2}{\|\mathbf{w}\|_2} $$ where $ \mathbf{w} $ is the normal vector of the **optimal** separating hyperplane that maximizes the minimum distance to the data points (i.e., the SVM-maximum-margin hyperplane). If no such hyperplane exists, output $-1$.
API Response (JSON)
{
  "problem": {
    "name": "F. Flow of Orz Pandas",
    "description": {
      "content": "There are $n$ villages in a county of the Orz Pandas. The $i$-th village needs $w_i$ tons of water per day. The Orz Pandas have built $k$ water supply facilities. The $i$-th water supply facility is l",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10287F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are $n$ villages in a county of the Orz Pandas. The $i$-th village needs $w_i$ tons of water per day. The Orz Pandas have built $k$ water supply facilities. The $i$-th water supply facility is l...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of data points.  \nLet $ P_i = (x_i, y_i, z_i) \\in \\mathbb{R}^3 $, $ i \\in \\{1, \\dots, n\\} $, be the coordinates of the data points.  \nLet $ c_i...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments