D. ShortestPath Query

Codeforces
IDCF10057D
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
De Prezer loves troyic paths.Consider we have a graph with n vertices and m edges.Edges are directed in one way.And there is at most one edge from any vertex to any other vertex.If there is an edge from v to u, then c(v, u) is its color and w(v, u) is its length.Otherwise,c(v, u) = w(v, u) =  - 1. A sequence p1, p2, ..., pk is a troyic path is and only if for each 1 ≤ i ≤ k, 1 ≤ pi ≤ n and if i < k, then c(pi, pi + 1) >  - 1 and if i + 1 < k, then c(pi, pi + 1) ≠ c(pi + 1, pi + 2) . The length of such troyic path is and it's called a p1 - pk path. In such graph, length of the shortest path from vertex v to u is the minimum length of all v - u paths.(The length of the shortest path from any vertex to itself equals 0) De Prezer gives you a graph like above and a vertex s. De Prezer also loves query. So he gives you q queries and in each query, gives you number t and you should print the length of the shortest path from s to t (or  - 1 if there is no troyic path from s to t) The first line of input contains three integers n and m and C, the number of vertices, the numbers of edges and the number of valid colors. The next m lines, each line contains 4 integers v, u, w(v, u), c(v, u) (1 ≤ v, u ≤ n and v ≠ u and 1 ≤ w(v, u) ≤ 109 and 1 ≤ c(v, u) ≤ C). The line after that contains integer s and q. The next q lines, each line contains information of one query, number t. 1 ≤ n, m, C, q ≤ 105 m ≤ n(n - 1) 1 ≤ s, t ≤ n For each query, print the answer. ## Input The first line of input contains three integers n and m and C, the number of vertices, the numbers of edges and the number of valid colors.The next m lines, each line contains 4 integers v, u, w(v, u), c(v, u) (1 ≤ v, u ≤ n and v ≠ u and 1 ≤ w(v, u) ≤ 109 and 1 ≤ c(v, u) ≤ C).The line after that contains integer s and q.The next q lines, each line contains information of one query, number t.1 ≤ n, m, C, q ≤ 105m ≤ n(n - 1)1 ≤ s, t ≤ n ## Output For each query, print the answer. [samples]
**Definitions** Let $ a, b \in \mathbb{Z}^+ $ with $ 1 \leq a, b \leq 10^5 $. **Objective** Compute $ c = \gcd(a, b) $, and store $ c $ in storage location 1.
API Response (JSON)
{
  "problem": {
    "name": "D. ShortestPath Query",
    "description": {
      "content": "De Prezer loves troyic paths.Consider we have a graph with n vertices and m edges.Edges are directed in one way.And there is at most one edge from any vertex to any other vertex.If there is an edge fr",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10057D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "De Prezer loves troyic paths.Consider we have a graph with n vertices and m edges.Edges are directed in one way.And there is at most one edge from any vertex to any other vertex.If there is an edge fr...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ a, b \\in \\mathbb{Z}^+ $ with $ 1 \\leq a, b \\leq 10^5 $.  \n\n**Objective**  \nCompute $ c = \\gcd(a, b) $, and store $ c $ in storage location 1....",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments