#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sort undefined_function // To use stable_sort instead sort
#define bpc __builtin_popcount
#define ull unsigned long long
#define ld double
#define ll long long
#define mp make_pair
#define F first
#define S second
#pragma GCC optimize("O3")
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace __gnu_pbds;
using namespace std;
typedef tree<long long, null_type, less_equal<long long>,
rb_tree_tag, tree_order_statistics_node_update> Tree;
const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
const ll MOD = 1e9 + 7; //[998244353, 1e9 + 7, 1e9 + 13]
const ld PI = acos(-1);
const ll NROOT = 500;
ll binpow(ll a, ll b, ll _MOD = -1) {
if (_MOD == -1)
_MOD = MOD;
ll res = 1;
for (; b; b /= 2, a *= a, a %= _MOD)
if (b & 1) res *= a, res %= _MOD;
return res;
}
void set_IO(string s) {
#ifndef LOCAL
string in = s + ".in";
string out = s + ".out";
freopen(in.c_str(), "r", stdin);
freopen(out.c_str(), "w", stdout);
#endif
}
bool dataOverflow(ll a, ll b) {return (log10(a) + log10(b) >= 18);}
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
ll ceil(ll a, ll b) {return (a + b - 1) / b;}
ll invmod(ll a) {return binpow(a, MOD - 2);}
int n, m, k;
vector<int> spec;
vector<vector<pair<int, ll>>> g;
bool cmp(pair<int, ll> a, pair<int, ll> b) {
if (a.S == b.S)
return a.F < b.F;
return a.S < b.S;
}
int solve() {
vector<int> dis1(n + 1, inf);
using T = pair<ll, int>;
priority_queue<T, vector<T>, greater<T>> q;
for (auto &x : g)
stable_sort(x.begin(), x.end(), cmp);
for (auto &x : spec)
q.push({0, x});
while (!q.empty()) {
auto [d, x] = q.top();
q.pop();
if (dis1[x] <= d)
continue;
dis1[x] = d;
dbg(x, d);
for (auto &y : g[x])
q.push({d + y.S, y.F});
}
dbg(dis1);
vector<int> dis2(n + 1, inf);
q.push({0, 1});
while (!q.empty()) {
auto [d, x] = q.top();
q.pop();
if (dis2[x] <= d)
continue;
dis2[x] = d;
vector<pair<pair<ll, ll>, pair<int, ll>>> ways;
for (auto &y : g[x])
ways.push_back({{dis1[y.F], y.S}, y});
stable_sort(ways.begin(), ways.end());
dbg(x, ways);
for (int i = 1; i < ways.size(); i ++) {
pair<int, ll> y = ways[i].S;
q.push({d + y.S, y.F});
}
}
dbg(dis2);
int ans = inf;
for (auto &x : spec)
ans = min(ans, dis2[x]);
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
g.resize(n + 1);
for (int i = 1; i <= m; i ++) {
int a, b, c;
cin >> a >> b >> c;
a ++; b ++;
g[a].push_back({b, c});
g[b].push_back({a, c});
}
for (int i = 1; i <= k; i ++) {
int x;
cin >> x;
x ++;
spec.push_back(x);
}
cout << solve() << "\n";
return 0;
}
Compilation message
crocodile.cpp: In function 'int solve()':
crocodile.cpp:18:19: warning: statement has no effect [-Wunused-value]
18 | #define dbg(...) 0
| ^
crocodile.cpp:87:3: note: in expansion of macro 'dbg'
87 | dbg(x, d);
| ^~~
crocodile.cpp:18:19: warning: statement has no effect [-Wunused-value]
18 | #define dbg(...) 0
| ^
crocodile.cpp:93:2: note: in expansion of macro 'dbg'
93 | dbg(dis1);
| ^~~
crocodile.cpp:18:19: warning: statement has no effect [-Wunused-value]
18 | #define dbg(...) 0
| ^
crocodile.cpp:111:3: note: in expansion of macro 'dbg'
111 | dbg(x, ways);
| ^~~
crocodile.cpp:113:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for (int i = 1; i < ways.size(); i ++) {
| ~~^~~~~~~~~~~~~
crocodile.cpp:18:19: warning: statement has no effect [-Wunused-value]
18 | #define dbg(...) 0
| ^
crocodile.cpp:119:2: note: in expansion of macro 'dbg'
119 | dbg(dis2);
| ^~~
crocodile.cpp: In function 'void set_IO(std::string)':
crocodile.cpp:46:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | freopen(in.c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
crocodile.cpp:47:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | freopen(out.c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccEm6Uo8.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc2vOy7a.o:crocodile.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccEm6Uo8.o: in function `main':
grader.cpp:(.text.startup+0x36): undefined reference to `travel_plan(int, int, int (*) [2], int*, int, int*)'
collect2: error: ld returned 1 exit status