B. Bakery

Codeforces
IDCF707B
Time2000ms
Memory256MB
Difficulty
graphs
Masha wants to open her own bakery and bake muffins in one of the _n_ cities numbered from 1 to _n_. There are _m_ bidirectional roads, each of whose connects some pair of cities. To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only _k_ storages, located in different cities numbered _a_1, _a_2, ..., _a__k_. Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another _n_ - _k_ cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble. Formally, Masha will pay _x_ roubles, if she will open the bakery in some city _b_ (_a__i_ ≠ _b_ for every 1 ≤ _i_ ≤ _k_) and choose a storage in some city _s_ (_s_ = _a__j_ for some 1 ≤ _j_ ≤ _k_) and _b_ and _s_ are connected by some path of roads of summary length _x_ (if there are more than one path, Masha is able to choose which of them should be used). Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of _k_ storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. ## Input The first line of the input contains three integers _n_, _m_ and _k_ (1 ≤ _n_, _m_ ≤ 105, 0 ≤ _k_ ≤ _n_) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then _m_ lines follow. Each of them contains three integers _u_, _v_ and _l_ (1 ≤ _u_, _v_ ≤ _n_, 1 ≤ _l_ ≤ 109, _u_ ≠ _v_) meaning that there is a road between cities _u_ and _v_ of length of _l_ kilometers . If _k_ > 0, then the last line of the input contains _k_ distinct integers _a_1, _a_2, ..., _a__k_ (1 ≤ _a__i_ ≤ _n_) — the number of cities having flour storage located in. If _k_ = 0 then this line **is not presented in the input**. ## Output Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the _n_ cities, print  - 1 in the only line. [samples] ## Note <center>![image](https://espresso.codeforces.com/ce17d1195580cb7b30943e16e8f7fe3caec0783b.png)Image illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. </center>
Samples
Input #1
5 4 2
1 2 5
1 2 3
2 3 4
1 4 10
1 5
Output #1
3
Input #2
3 1 1
1 2 3
3
Output #2
\-1
API Response (JSON)
{
  "problem": {
    "name": "B. Bakery",
    "description": {
      "content": "Masha wants to open her own bakery and bake muffins in one of the _n_ cities numbered from 1 to _n_. There are _m_ bidirectional roads, each of whose connects some pair of cities. To bake muffins in ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF707B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Masha wants to open her own bakery and bake muffins in one of the _n_ cities numbered from 1 to _n_. There are _m_ bidirectional roads, each of whose connects some pair of cities.\n\nTo bake muffins in ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments