rendered paste body/*ID: SupoPROG: butterLANG: C++*///DEDICATED TO EMMA WATSON, THE BRITISH *SUNSHINE*#include <vector>#include <list>#include <map>#include <set>#include <deque>#include <stack>#include <bitset>#include <algorithm>#include <functional>#include <numeric>#include <utility>#include <sstream>#include <iostream>#include <iomanip>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>#include <fstream>#define eps 10e-10#define INF 10000000#define PI 3.141592653589793238462#define EU 2.71828182845904523536#define sz(a) (int)a.size()#define pb(a) push_back(a)#define mset(a,hodnota) memset(a,hodnota,sizeof(a))#define wh(a) a.begin(),a.end()#define REP(i,n) for(__typeof(n) i=0;i<(n);++i)#define REPS(i,n) for(int(i)=0;i<int(n.size());++i)#define FOR(i,a,b) for(__typeof(b) i=(a);i<=(b);++i)#define FORD(i,a,b) for(__typeof(a) i=(a);i>=(b);--i)#define FORE(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)#define pii pair<int,int>#define mp(a,b) make_pair(a,b)#define fi first#define se secondtypedef long long ll;using namespace std;ifstream fin ("butter.in");ofstream fout ("butter.out");int cows[805];vector<pair<int,int> > edges[805];int res[805],dist[805];int main( ){ int P,C,N; fin>>N>>P>>C; REP(i,N) fin>>cows[i],cows[i]--; REP(i,C) { int a,b,w; fin>>a>>b>>w;a--,b--; edges[a].pb(mp(b,w)); edges[b].pb(mp(a,w)); } REP(i,N) { cout<<i<<endl; memset(dist,0x3F,sizeof(dist)); dist[cows[i]]=0; set<pair<int,int> > Q; Q.insert(mp(0,cows[i])); while(sz(Q)) { pair<int,int> top=*Q.begin(); Q.erase(Q.begin()); REPS(j,edges[top.second]) if (dist[edges[top.second][j].first]>dist[top.second]+edges[top.second][j].second) { Q.erase(mp(dist[edges[top.second][j].first],edges[top.second][j].first)); dist[edges[top.second][j].first]=dist[top.second]+edges[top.second][j].second; Q.insert(mp(dist[edges[top.second][j].first],edges[top.second][j].first)); } } REP(j,P) res[j]+=dist[j]; } fout<<*min_element(res,res+P)<<endl; return 0;}