{"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 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.\n\nA 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) .\n\nThe length of such troyic path is  and it's called a p1 - pk path.\n\nIn 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)\n\nDe Prezer gives you a graph like above and a vertex s.\n\nDe 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)\n\nThe 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.\n\nThe 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).\n\nThe line after that contains integer s and q.\n\nThe next q lines, each line contains information of one query, number t.\n\n1 ≤ n, m, C, q ≤ 105\n\nm ≤ n(n - 1)\n\n1 ≤ s, t ≤ n\n\nFor each query, print the answer.\n\n## Input\n\nThe 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\n\n## Output\n\nFor each query, print the answer.\n\n[samples]","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"}],"meta":{"iden":"CF10057D","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}