#include #include #include #define endl '\n' #define fi first #define se second using namespace std; const double TIME_LIMIT = 4.800; chrono::time_point tmr_begin; void initClock() { tmr_begin = chrono::steady_clock::now(); } double getTime() { return 1e-3 * chrono::duration_cast(chrono::steady_clock::now() - tmr_begin).count(); } void fileInOut() { freopen("transport.in", "r", stdin); freopen("transport.out", "w", stdout); } void fastIO() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int MAXN = 205; const int MAXG = 1005; const int MAXM = 1005; const int T=2000; const int INF = 1e9 + 5; const long long INFLL = (long long)1e18 + 5; mt19937 mt(666); struct Route { int t; vector kids; //vector path; int dest; /*Route() { t=0; kids=vector(); dest=0; }*/ }; int n,m,g; vector > adj[MAXN]; int twn[MAXG]; vector kids[MAXN]; pair cost[MAXN][2005]; priority_queue > pq; bool used[MAXN]; int dist[MAXN]; int par[MAXN]; vector perm; vector routes; bool usedT[2005]; long long bestCost=INFLL; vector bestPerm; void dijkstra(int s) { for(int i=1;i<=n;i++) used[i]=0; for(int i=1;i<=n;i++) dist[i]=INF; dist[s]=0; par[s]=-1; pq.push({0,s}); while(!pq.empty()) { int v=pq.top().se; pq.pop(); if(used[v]) continue; used[v]=1; for(auto [u,w]: adj[v]) { if(!used[u] && dist[v]+w0) { int cur=min(cnt, 4); cnt-=cur; while(usedT[cost[town][ptr].se]) ptr++; usedT[cost[town][ptr].se]=1; curCost+=1LL*dist[town]*(cur)*cost[town][ptr].fi; } } if(curCost tmp=kids[town]; int ptr=1; while(!tmp.empty()) { routes.push_back(Route()); routes.back().dest=town; int sz=tmp.size(); for(int j=0;j path; int v=cur.dest; do { path.push_back(v); v=par[v]; }while(v!=-1); reverse(path.begin(), path.end()); cout<>n>>m>>g; for(int i=1;i<=g;i++) cin>>twn[i]; for(int i=1;i<=n;i++) { for(int j=1;j<=T;j++) { cin>>cost[i][j].fi; cost[i][j].se=j; } } for(int i=0;i>u>>v>>w; adj[u].push_back({v,w}); adj[v].push_back({u,w}); } dijkstra(1); for(int i=1;i<=g;i++) { kids[twn[i]].push_back(i); } perm.resize(n); iota(perm.begin(), perm.end(), 1); for(int i=1;i<=n;i++) { sort(cost[i]+1, cost[i]+T+1); } for(;getTime()