This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define nn "\n"
#define x_x ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define intt int _; cin >> _; while (_--)
#define emp push_back
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define ld long double
#define A first
#define B second
//#define int long long
typedef long long ll;
const ld eps = 1e-27;
// diff between decimals 0.000000001 mt19937 mt(time(nullptr));
struct ed {
int f; int t; ll w;
};
int main() {
x_x
int n,k,m; cin>>n>>m>>k; vector<ed>adj;
for (int i=0,a,b,c; i<m; i++)
cin>>a>>b>>c, adj.emp({a,b,c}), adj.emp({b,a,c});
int sp[n+2]={}; ll dis[n+2]; for (int i=0,x;i<k; i++) cin>>x, sp[x]=1;
vector<ed>v;
for (int z=1; z<=n; z++) {
if (!sp[z]) continue;
for (auto&i:dis)i=1e15;
dis[z]=0;
for (int nm=0; nm<=n+2; nm++) {
for (auto i:adj) {
if (dis[i.t]>(dis[i.f]+i.w))
dis[i.t]=(dis[i.f]+i.w);
}
}
for (int i=z+1; i<=n; i++)
if (sp[i]) v.emp({z,i,dis[i]});
}
ll ans=LLONG_MAX;
for (int i=0; i<v.size(); i++) {
for (int j=i+1; j<v.size(); j++)
if (v[i].f!=v[j].f&&v[i].t!=v[j].t&&v[i].f!=v[j].t&&v[i].t!=v[j].f)
ans=min(ans, v[i].w+v[j].w);
}
cout<<ans;
return 0;
}
Compilation message (stderr)
RelayMarathon.cpp: In function 'int main()':
RelayMarathon.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ed>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int i=0; i<v.size(); i++) {
| ~^~~~~~~~~
RelayMarathon.cpp:47:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ed>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int j=i+1; j<v.size(); j++)
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |