#include<iostream> #include<vector> #include<cstring> #include<queue> usingnamespace std; typedeflonglong ll; typedef pair<ll, ll> PII; constint N = 1010; int n, m, k, sta; structEdge { int v, w; }; vector<Edge> g[N]; bool vis[N]; int dis[N]; int f[N][N]; voiddijstra(){ int s = sta; memset(vis, 0, sizeof(vis)); memset(dis, 0x3f, sizeof(dis)); dis[s] = 0; priority_queue<PII, vector<PII>, greater<PII> > q; q.push({dis[s], s}); while (!q.empty()) { PII e = q.top(); q.pop(); int v = e.second; if (vis[v]) continue; vis[v] = 1; for (int i = 0; i < g[v].size(); i++) { Edge e = g[v][i]; if (dis[e.v] > dis[v] + e.w) { dis[e.v] = dis[v] + e.w; q.push({dis[e.v], e.v}); } } } for (int i = 1; i <= n; i++) { f[s][i] = dis[i]; } } intmain(){ cin >> n >> m >> k; vector<PII> edge; for (int i = 1; i <= m; i++) { int u, v, w; cin >> u >> v >> w; g[u].push_back({v, w}); g[v].push_back({u, w}); edge.push_back({u ,v}); } vector<PII> v; for (int i = 1; i <= k; i++) { int a, b; cin >> a >> b; v.push_back({a ,b}); } for (int i = 1; i <= n; i++) { sta = i; dijstra(); } int sum = 0x3f3f3f3f; for (auto i : edge) { int a = i.first, b = i.second; int ans = 0; for (auto j : v) { ans += min(f[j.first][j.second], min(f[j.first][a] + f[j.second][b], f[j.second][a] + f[j.first][b])); } sum = min(ans, sum); } cout << sum << endl; return0; }