Problem:
E: ジャム (Jam)
問題
ある国には
N
個の街があり、
1,\ 2,\ ...,\ N
の番号がつけられています。これらの街は
M
本の道で双方向に結ばれており、
i
番目の道を使うと街
u_i
と
v_i
の間を時間
t_i
で移動することができます。また、どの
2
つの街もいくつかの道を使うことで行き来することができます。
それぞれの街では食パンが売られており、街
i
で売られている食パンの美味しさは
P_i
です。
さらに、この国には
K
種類の味のジャムがあり、街
i
では味
c_i
で美味しさ
J_i
のジャムを買うことができます。
街
1
に住んでいるほむちゃんは、これからパンとジャムを
1
つずつ買いにお出かけすることにしました。ほむちゃんは、いくつかの街を移動してパンとジャムを買って街
1
に戻ってきます。より正確には、ある街
u
に移動してパンを買い、ある街
v
を選んでジャムを買い、街
1
に戻ってきます。この際、
u=v
や
u=1
、
v=1
でも構いません。
お買い物を終えたほむちゃんの幸福度は、「買ったパンとジャムの美味しさの合計」ー「移動にかかった時間」です。
K
種類それぞれのジャムについて、その味のジャムとパンを買いに行くときの幸福度として考えられる最大値を計算してください。
入力形式
N
M
K
P_1
P_2
...
P_N
c_1
c_2
...
c_N
J_1
J_2
...
J_N
u_1
v_1
t_1
u_2
v_2
t_2
:
u_M
v_M
t_M
制約
1\leq N\leq 10^5
1\leq M\leq 2\times 10^5
1\leq K\leq N
1\leq P_i, J_i\leq 10^9
1\leq c_i\leq K
1\leq u_i, v_i \leq N
1\leq t_i \leq 10^9
すべての
i\ (1\leq i\leq K)
について、
c_j=i
となる
j\ (1\leq j\leq N)
が存在する
与えられるグラフは多重辺や自己ループを含まない連結なグラフである
入力はすべて整数で与えられる
出力形式
K
行出力してください。
i
行目にはパンと味
i
のジャムを買いに行く場合の幸福度の最大値を出力してください。
入力例 1
4 4 3
3 6 1 6
1 1 2 3
6 1 5 5
1 2 1
2 3 1
1 3 1
1 4 1
出力例 1
10
8
9
味
1
のジャムを買う場合
街
1
でジャムを買い、街
2
に移動してパンを買い、街
1
に戻ってくると、幸福度は
6+6-2=10
となりこれが最適です。
味
2
のジャムを買う場合
街
2
に移動してパンを買い、街
3
に移動してジャムを買い、街
1
に戻ってくると、幸福度は
6+5-3=8
となります。
味
3
のジャムを買う場合
街
4
に移動してパンとジャムの両方を買って街
1
に戻ってくると、幸福度は
6+5-2=9
となります。
入力例 2
2 1 2
1 1
1 2
1 1
1 2 1000000000
出力例 2
2
-1999999998
パンやジャムの美味しさに比べて距離が遠すぎるのでほむちゃんは不満そうです。
入力例 3
6 8 3
31 41 59 26 53 58
1 2 3 1 2 3
27 18 28 18 28 46
1 2 3
2 3 7
2 4 8
3 6 9
3 5 3
4 5 3
1 5 15
4 6 7
出力例 3
66
61
68

Submitted solutions:

code_snippet: #include <bits/stdc++.h>

using usize = std::size_t;
using i64 = long long;

struct SPFAGraph {
  using edge = std::pair< usize, i64 >;

  std::vector< std::vector< edge > > g;

  SPFAGraph(usize n) : g(n) {}

  void add_directed_edge(usize from, usize to, i64 cost) {
    g[from].emplace_back(to, cost);
  }

  std::vector< i64 > dijkstra(usize s) {
    usize n = g.size();
    constexpr i64 inf = std::numeric_limits<i64>::max();
    std::vector< i64 > ds(n, inf);

    using P = std::pair< i64, usize >;
    std::priority_queue< P, std::vector< P >, std::greater< P > > pq;

    ds[s] = 0;
    pq.emplace(ds[s], s);

    while (not pq.empty()) {
      auto [cost, v] = pq.top();
      pq.pop();

      if (cost > ds[v]) continue;

      for (auto [u, c]: g[v]) {
        if (ds[u] > ds[v] + c) {
          ds[u] = ds[v] + c;
          pq.emplace(ds[u], u);
        }
      }
    }

    return ds;
  }
};

int main() {
  usize n, m, k;
  std::cin >> n >> m >> k;

  constexpr i64 B = 1e9;

  std::vector< i64 > ps(n), js(n);
  std::vector< usize > cs(n);

  for (auto &p: ps) {
    std::cin >> p;
  }
  for (auto &c: cs) {
    std::cin >> c;
    c--;
  }
  for (auto &j: js) {
    std::cin >> j;
  }

  usize V = n + k + 1;
  usize S = n + k;
  SPFAGraph g(V);

  for (usize i = 0; i < m; i++) {
    usize u, v;
    i64 c;
    std::cin >> u >> v >> c;
    u--; v--;
    g.add_directed_edge(u, v, c);
    g.add_directed_edge(v, u, c);
  }

  auto dists = g.dijkstra(0);

  for (usize v = 0; v < n; v++) {
    g.add_directed_edge(S, v, B - ps[v] + dists[v]);
    g.add_directed_edge(v, n + cs[v], B - js[v] + dists[v]);
  }

  auto ans = g.dijkstra(S);
  for (usize v = 0; v < k; v++) {
    std::cout << 2 * B - ans[v + n] << std::endl;
  }
}
accuracy: 1
time_ms: 300
memory_kb: 32400
final_rank: 11

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=1167167167167167167;
const int INF=10000000;

#define rep(i,a) for (int i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}
using len_type=ll;
struct edge{
    int to;
    len_type length;
};

len_type dijkstra_movement(edge e,int from,len_type t){
    return t+e.length;
}


vector<len_type> dijkstra(vector<vector<edge>> &G,int start,len_type inf){
    int M=G.size();
    assert(M>start&&start>=0);
    vector<len_type> seen(M,inf);
    seen[start]=0;
    priority_queue<pair<len_type,int>,vector<pair<len_type,int>>,greater<pair<len_type,int>>> pq;
    pq.push({0,start});
    while(!pq.empty()){
        len_type time;
        int ver;
        tie(time,ver)=pq.top();
        pq.pop();
        if(seen[ver]<time) continue;
        for(edge x:G[ver]){
            len_type T=dijkstra_movement(x,ver,time);
            if(T<seen[x.to]){
                pq.push({T,x.to});
                seen[x.to]=T;
            }
        }
    }
    return seen;
}


void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N,M,K;
	cin>>N>>M>>K;
	vector<vector<edge>> G(N*2);
	rep(i,N){
		ll p;
		cin>>p;
		G[i].push_back({N+i,ILL-p});
	}
	vector<ll> c(N),ans(K,-ILL*3),J(N);
	rep(i,N) cin>>c[i],c[i]--;
	rep(i,N) cin>>J[i];
	rep(i,M){
		int a,b,t;
		cin>>a>>b>>t;
		a--,b--;
		G[a].push_back({b,t});
		G[b].push_back({a,t});
		G[a+N].push_back({b+N,t});
		G[b+N].push_back({a+N,t});
	}
	auto seen=dijkstra(G,0,ILL*3);
	rep(i,N){
		chmax(ans[c[i]],J[i]-seen[i]-seen[i+N]+ILL);
	}
	rep(i,K) cout<<ans[i]<<"\n";
}
accuracy: 1
time_ms: 180
memory_kb: 35808
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

using Edge = pair<long long, int>;
using Graph = vector<vector<Edge>>;

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<long long> P(N), C(N), J(N);
    for (int i = 0; i < N; ++i) cin >> P[i];
    for (int i = 0; i < N; ++i) cin >> C[i];
    for (int i = 0; i < N; ++i) cin >> J[i];
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int u, v;
        long long t;
        cin >> u >> v >> t;
        --u, --v;
        G[u].emplace_back(v, t);
        G[v].emplace_back(u, t);
    }

    const long long INF = 1LL<<60;
    const long long GETA = 1LL<<30;
    vector<long long> dp1(N, INF), dp2(N, INF); // notuse pan, use pan
    using pint = pair<int,int>; // vertex, (notuse pan: 0, use pan: 1)
    priority_queue<pair<long long, pint>,
                   vector<pair<long long, pint>>,
                   greater<pair<long long, pint>>> que;
    dp1[0] = 0;
    que.push({0, pint(0, 0)});
    while (!que.empty()) {
        auto p = que.top(); que.pop();
        long long cur = p.first;
        int v = p.second.first, parity = p.second.second;

        if (parity == 0 && cur > dp1[v]) continue;
        if (parity == 1 && cur > dp2[v]) continue;

        if (parity == 0) {
            if (chmin(dp2[v], dp1[v] - P[v] + GETA)) {
                que.push({dp2[v], pint(v, 1)});
            }
            for (auto e : G[v]) {
                int nv = e.first, w = e.second;
                if (chmin(dp1[nv], dp1[v] + w)) {
                    que.push({dp1[nv], pint(nv, 0)});
                }
            }
        }
        else {
            for (auto e : G[v]) {
                int nv = e.first, w = e.second;
                if (chmin(dp2[nv], dp2[v] + w)) {
                    que.push({dp2[nv], pint(nv, 1)});
                }
            }
        }
    }

    vector<long long> res(K, -INF);
    for (int v = 0; v < N; ++v) {
        chmax(res[C[v]-1], J[v] - (dp1[v] + dp2[v] - GETA));
    }
    for (auto v : res) cout << v << endl;
}
accuracy: 1
time_ms: 280
memory_kb: 23976
final_rank: 6

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {if (a > b) a = b;}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {if (a < b) a = b;}
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;
// const int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };

struct edge { int to, cost; };
int V;//頂点数
vector<edge>G[MAX];
int d[MAX];

using P = pii;
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>que;
	fill(d, d + V, LINF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

void solve() {
	int N, M, K; cin >> N >> M >> K;
	vector<int>p(N);
	REP(i, N)cin >> p[i];
	vector<int>C(N), J(N);
	REP(i, N)cin >> C[i];
	REP(i, N)C[i]--;
	REP(i, N)cin >> J[i];
	REP(i, N) {
		G[i].push_back({ i + N,INF - p[i] });
	}
	REP(_, M) {
		int u, v, t;
		cin >> u >> v >> t;
		u--, v--;
		G[u].push_back({ v,t });
		G[u + N].push_back({ v + N,t });
		G[v].push_back({ u,t });
		G[v + N].push_back({ u + N,t });
	}
	V = N * 2;
	dijkstra(0);
	vector<int>ans(K, -LINF);
	REP(i, N) {
		ll res =-( d[i + N] + d[i])+INF+J[i];
		chmax(ans[C[i]], res);
	}
	REP(i, K)print(ans[i]);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	 //int q;
	 //cin >> q;
	 //while (q--)
	solve();
}
accuracy: 1
time_ms: 230
memory_kb: 43152
final_rank: 16

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* Dijkstra O(NlogM)*/

template <typename Type = int>
struct Dijkstra{
  int V;
  vector<vector<pair<int,Type>>> G;
  vector<Type> cost;

  Dijkstra(int n):
    V(n), G(n, vector<pair<int,Type>>()) {}

  void add_edge(int u, int v, Type c){
    G[u].push_back({v, c});
  }

  Type solve(int s, int g = -1){
    cost.assign(V, -1);
    priority_queue<pair<Type,int>> pq;
    Type max_cost = 0;

    pq.push({0, s});

    while(pq.size()){
      Type now_cost = pq.top().first;
      int now = pq.top().second;
      pq.pop();

      if(cost[now] >= 0) continue;

      cost[now] = -now_cost;
      max_cost = max(max_cost, -now_cost);

      if(now == g) return -now_cost;

      for(int i=0; i<(int)G[now].size(); i++)
        pq.push({now_cost - G[now][i].second, G[now][i].first});
    }

    return max_cost;
  }
};

int N, M, K;
ll J[SIZE], P[SIZE], c[SIZE];
vector<pair<int,int>> G[SIZE];

int main(){

  scanf("%d%d%d", &N, &M, &K);

  for (int i=0; i<N; i++) scanf("%lld", P+i);
  for (int i=0; i<N; i++) scanf("%lld", c+i);
  for (int i=0; i<N; i++) scanf("%lld", J+i);

  Dijkstra<ll> dijk(N);

  for (int i=0; i<M; i++) {
    int u, v, t;
    scanf("%d%d%d", &u, &v, &t);
    u--; v--;
    G[u].push_back({v, t});
    G[v].push_back({u, t});
    dijk.add_edge(u, v, t);
    dijk.add_edge(v, u, t);
  }

  dijk.solve(0);

  priority_queue<pair<ll,int>> pq;

  for (int i=0; i<N; i++) {
    J[i] -= dijk.cost[i];
    P[i] -= dijk.cost[i];
    pq.push({P[i], i});
  }

  bool visited[SIZE] = {};
  ll T[SIZE];
  while(pq.size()) {
    auto p = pq.top();
    pq.pop();

    int now = p.second;
    ll cost = p.first;

    if (visited[now]) continue;
    visited[now] = true;

    T[now] = cost;

    for (auto q : G[now]) {
      if (!visited[q.first]) {
        pq.push({cost - q.second, q.first});
      }
    }
  }

  ll ans[SIZE];

  for (int i=0; i<K; i++)
    ans[i] = -LLINF;

  for (int i=0; i<N; i++) {
    ans[c[i]-1] = max(ans[c[i]-1], J[i] + T[i]);
  }

  for (int i=0; i<K; i++) {
    printf("%lld\n", ans[i]);
  }

  return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 36820
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


template <typename T>
vector<T> dijkstra(Int s,vector<vector<pair<Int, T> > > & G){
  const T INF = numeric_limits<T>::max();
  using P = pair<T, Int>;
  Int n=G.size();
  vector<T> d(n,INF);
  vector<Int> b(n,-1);
  priority_queue<P,vector<P>,greater<P> > q;
  d[s]=0;
  q.emplace(d[s],s);
  while(!q.empty()){
    P p=q.top();q.pop();
    Int v=p.second;
    if(d[v]<p.first) continue;
    for(auto& e:G[v]){
      Int u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
        d[u]=d[v]+c;
        b[u]=v;
        q.emplace(d[u],u);
      }
    }
  }
  return d;
}

//INSERT ABOVE HERE
signed main(){
  Int n,m,k;
  cin>>n>>m>>k;
  vector<Int> ps(n),cs(n),js(n);
  for(Int i=0;i<n;i++) cin>>ps[i];
  for(Int i=0;i<n;i++) cin>>cs[i],cs[i]--;
  for(Int i=0;i<n;i++) cin>>js[i];

  using P = pair<Int, Int>;
  vector< vector<P> > G(n+1);
  for(Int i=0;i<m;i++){
    Int u,v,t;
    cin>>u>>v>>t;
    u--;v--;
    G[u].emplace_back(v,t);
    G[v].emplace_back(u,t);
  }

  auto ds=dijkstra(0,G);

  const Int OFS = 2e9;
  for(Int i=0;i<n;i++)
    G[n].emplace_back(i,ds[i]-ps[i]+OFS);

  auto dt=dijkstra(n,G);
  const Int INF = 1e18;
  vector<Int> ans(k,-INF);
  for(Int i=0;i<n;i++)
    chmax(ans[cs[i]],js[i]-(dt[i]-OFS+ds[i]));

  for(Int x:ans) cout<<x<<"\n";
  cout<<flush;
  return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 24468
final_rank: 3

code_snippet: /*  -*- coding: utf-8 -*-
 *
 * 2956.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_K = MAX_N;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<pii> vpii;

/* global variables */

int ps[MAX_N], cs[MAX_N], js[MAX_N];
vpii nbrs[MAX_N];
ll dp0[MAX_N], dp1[MAX_N], maxhs[MAX_K];

/* subroutines */

void dijkstra(priority_queue<pli> &q, ll dp[]) {
  while (! q.empty()) {
    pli u = q.top(); q.pop();
    ll &ud = u.first;
    int &ui = u.second;
    if (ud != dp[ui]) continue;

    vpii &nbru = nbrs[ui];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &vi = vit->first;
      ll vd = ud - vit->second;
      if (dp[vi] < vd) {
	dp[vi] = vd;
	q.push(pli(vd, vi));
      }
    }
  }
}

/* main */

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);

  for (int i = 0; i < n; i++) scanf("%d", ps + i);
  for (int i = 0; i < n; i++) scanf("%d", cs + i), cs[i]--;
  for (int i = 0; i < n; i++) scanf("%d", js + i);

  for (int i = 0; i < m; i++) {
    int u, v, t;
    scanf("%d%d%d", &u, &v, &t);
    u--, v--;
    nbrs[u].push_back(pii(v, t));
    nbrs[v].push_back(pii(u, t));
  }

  fill(dp0, dp0 + n, -LINF);
  dp0[0] = 0;

  priority_queue<pli> q;
  q.push(pli(0, 0));
  dijkstra(q, dp0);

  fill(dp1, dp1 + n, -LINF);
  for (int i = 0; i < n; i++) {
    ll d = dp0[i] + ps[i];
    dp1[i] = d;
    q.push(pli(d, i));
  }
  dijkstra(q, dp1);

  fill(maxhs, maxhs + k, -LINF);

  for (int i = 0; i < n; i++) {
    ll h = dp1[i] + js[i] + dp0[i];
    if (maxhs[cs[i]] < h) maxhs[cs[i]] = h;
  }

  for (int i = 0; i < k; i++) printf("%lld\n", maxhs[i]);
  return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 16824
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

struct Edge {
	int to, cost;
};
int main() {
	int n, m, k; std::cin >> n >> m >> k;
	std::vector<int> bread_taste(n), jam_taste(n);
	std::vector<std::vector<int>> jam_type(k);
	for (auto& p : bread_taste) std::cin >> p;
	for (auto i = 0; i < n; ++i) {
		int c; std::cin >> c;
		jam_type[c - 1].push_back(i);
	}
	for (auto& j : jam_taste) std::cin >> j;
	std::vector<std::vector<Edge>> towns(n);
	for (auto i = 0; i < m; ++i) {
		int u, v, t; std::cin >> u >> v >> t;
		towns[u - 1].push_back({ v - 1, t });
		towns[v - 1].push_back({ u - 1, t });
	}
	auto comparator = [](const std::pair<int, long long int>& a, const std::pair<int, long long int>& b) {return a.second > b.second; };
	std::priority_queue<std::pair<int, long long int>, std::vector<std::pair<int, long long int>>, decltype(comparator)> queue(comparator);
	std::vector<long long int> min_time_from_start(n, LLONG_MAX); min_time_from_start[0] = 0; queue.emplace(0, 0);
	while (!queue.empty()) {
		auto top = queue.top(); queue.pop();
		if (min_time_from_start[top.first] == top.second) {
			for (const auto& e : towns[top.first]) {
				if (min_time_from_start[e.to] > top.second + e.cost) {
					min_time_from_start[e.to] = top.second + e.cost;
					queue.emplace(e.to, top.second + e.cost);
				}
			}
		}
	}
	std::vector<long long int> min_cost_for_bread(n);
	for (auto i = 0; i < n; ++i) min_cost_for_bread[i] = min_time_from_start[i] - bread_taste[i];
	std::vector<long long int> min_cost_for_jam(min_cost_for_bread);
	for (auto i = 0; i < n; ++i) queue.emplace(i, min_cost_for_jam[i]);
	while (!queue.empty()) {
		auto top = queue.top(); queue.pop();
		if (min_cost_for_jam[top.first] == top.second) {
			for (const auto& e : towns[top.first]) {
				if (min_cost_for_jam[e.to] > top.second + e.cost) {
					min_cost_for_jam[e.to] = top.second + e.cost;
					queue.emplace(e.to, top.second + e.cost);
				}
			}
		}
	}
	for (auto i = 0; i < n; ++i) min_cost_for_jam[i] -= jam_taste[i];
	std::vector<long long int> min_cost_for_all(min_time_from_start);
	for (auto i = 0; i < n; ++i) min_cost_for_all[i] += min_cost_for_jam[i];
	for (auto type = 0; type < k; ++type) {
		std::cout << -min_cost_for_all[*std::min_element(jam_type[type].begin(), jam_type[type].end(), [&min_cost_for_all](const int i, const int j) {return min_cost_for_all[i] < min_cost_for_all[j]; })] << std::endl;
	}
}
accuracy: 1
time_ms: 360
memory_kb: 21552
final_rank: 5

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

struct Edge{
	Edge(int arg_to,ll arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	int to;
	ll cost;
};

struct State{
	State(int arg_node_id,ll arg_sum_cost){
		node_id = arg_node_id;
		sum_cost = arg_sum_cost;
	}
	bool operator<(const struct State &arg) const{
		return sum_cost > arg.sum_cost; //総コストの昇順(PQ)
	}

	int node_id;
	ll sum_cost;
};

int V,E,K;
ll P[SIZE],c[SIZE],J[SIZE],ans[SIZE];
ll min_cost[2*SIZE];
vector<Edge> G[2*SIZE];


int main(){

	scanf("%d %d %d",&V,&E,&K);

	for(int i = 0; i < V; i++){

		scanf("%lld",&P[i]);
	}

	for(int i = 0; i < V; i++){

		scanf("%lld",&c[i]);
		c[i]--;
	}

	for(int i = 0; i < V; i++){

		scanf("%lld",&J[i]);
	}

	int from,to;
	ll cost;

	for(int loop = 0; loop < E; loop++){

		scanf("%d %d %lld",&from,&to,&cost);
		from--;
		to--;

		G[from].push_back(Edge(to,cost));
		G[to].push_back(Edge(from,cost));

		G[V+from].push_back(Edge(V+to,cost));
		G[V+to].push_back(Edge(V+from,cost));
	}

	for(int from = 0; from < V; from++){

		int to = V+from;
		G[from].push_back(Edge(to,-P[from]+BIG_NUM));
	}


	min_cost[0] = 0;
	for(int i = 1; i < 2*V; i++){

		min_cost[i] = HUGE_NUM;
	}

	priority_queue<State> Q;
	Q.push(State(0,0));

	while(!Q.empty()){

		if(Q.top().sum_cost > min_cost[Q.top().node_id]){

			Q.pop();

		}else{

			for(int i = 0; i < G[Q.top().node_id].size(); i++){

				int next_node = G[Q.top().node_id][i].to;
				ll next_cost = Q.top().sum_cost+G[Q.top().node_id][i].cost;

				if(min_cost[next_node] > next_cost){

					min_cost[next_node] = next_cost;
					Q.push(State(next_node,next_cost));
				}

			}

			Q.pop();
		}
	}

	for(int i = 0; i < K; i++){

		ans[i] = HUGE_NUM;
	}

	for(int i = 0; i < V; i++){

		ans[c[i]] = min(ans[c[i]],min_cost[i]+min_cost[V+i]-BIG_NUM-J[i]);
	}

	for(int i = 0; i < K; i++){

		printf("%lld\n",-ans[i]);
	}

	return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 37816
final_rank: 15

code_snippet: // #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const ll inf = 1e18;

V<ll> dijk(ll start, const VV<PLL> &edges) {
    size_t node_cnt = edges.size();
    V<ll> dists(node_cnt, inf);
    dists[start] = 0;
    priority_queue<PLL, V<PLL>, greater<PLL>> pq;
    pq.emplace(0, start);
    while(pq.size()) {
        ll dist, now;
        tie(dist, now) = pq.top();
        pq.pop();
        if(dists[now] < dist) continue;
        for(auto &&edge : edges[now]) {
            ll nxt, cost;
            tie(nxt, cost) = edge;
            ll nxt_dist = dist + cost;
            if(dists[nxt] <= nxt_dist) continue;
            dists[nxt] = nxt_dist;
            pq.emplace(nxt_dist, nxt);
        }
    }
    return dists;
}

void input(V<ll> &v) { for(auto &&ele : v) cin >> ele; }

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    V<ll> pan(N), jam_k(N), jam_h(N);
    input(pan);
    input(jam_k);
    input(jam_h);
    for(auto &&ele : jam_k) ele--;
    VV<PLL> edges(N);
    for(ll i = 0; i < M; i++) {
        ll u, v, t;
        cin >> u >> v >> t;
        u--; v--;
        edges[u].emplace_back(v, t);
        edges[v].emplace_back(u, t);
    }

    auto dist_from_init = dijk(0, edges);
    ll start = 2 * N;
    VV<PLL> edges_to_jam(2 * N + 1);
    const ll base = 5e15;
    for(ll i = 0; i < N; i++) {
        edges_to_jam[start].emplace_back(i + N, base - (pan[i] - dist_from_init[i]));
        edges_to_jam[i + N].emplace_back(i, 0);
        edges_to_jam[i] = move(edges[i]);
    }

    auto dist_from_pan = dijk(start, edges_to_jam);
    V<ll> ans(K, -inf);
    for(ll i = 0; i < N; i++) {
        ll dist = dist_from_pan[i];
        dist = base - dist;
        ll happiness = dist + jam_h[i] - dist_from_init[i];
        chmax(ans[jam_k[i]], happiness);
    }
    for(auto &&ele : ans) cout << ele << endl;
    return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 32936
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll=long long;
struct Edge{
    int to;
    ll w;
};
const ll INF=1e17;
using Graph=vector<vector<Edge>>;
class Solver{
    int n,m,k;
    vector<ll> p;
    vector<ll> c;
    vector<ll> j;
    Graph g;
    vector<ll> res;
    
    vector<ll> Dijkstra(vector<ll> d){
        int n=d.size();
        using Item=pair<ll,int>;
        priority_queue<Item,vector<Item>,greater<>> que;
        for(int i=0;i<n;i++) que.push(make_pair(d[i],i));
        while(!que.empty()){
            auto tmp=que.top(); que.pop();
            int v=tmp.second;
            if(d[v]<tmp.first) continue;
            for(auto& e:g[v]){
                if(d[e.to]>d[v]+e.w){
                    d[e.to]=d[v]+e.w;
                    que.push(make_pair(d[e.to],e.to));
                }
            }
        }
        return d;
    }
    public:
    Solver(int n,int m,int k):n(n),m(m),k(k),p(n),c(n),j(n),g(n),res(k,-INF){
        for(int i=0;i<n;i++) cin>>p[i];
        for(int i=0;i<n;i++) cin>>c[i],c[i]--;
        for(int i=0;i<n;i++) cin>>j[i];
        for(int i=0;i<m;i++){
            int u,v,t; cin>>u>>v>>t;
            u--,v--;
            g[u].push_back(Edge{v,t});
            g[v].push_back(Edge{u,t});
        }
    }
    void solve(){
        vector<ll> d1(n,INF);
        d1[0]=0;
        d1=Dijkstra(d1);
        auto d2=d1;
        for(int i=0;i<n;i++) d2[i]-=p[i];
        auto d3=Dijkstra(d2);
        for(int i=0;i<n;i++){
            res[c[i]]=max(res[c[i]],j[i]-d1[i]-d3[i]);
        }
        return;
    }
    void print(){
        for(int i=0;i<k;i++){
            cout<<res[i]<<endl;
        }
    }
};
int main(){
    int n,m,k;
    cin>>n>>m>>k;
    Solver solver(n,m,k);
    solver.solve();
    solver.print();
    return 0;
}
accuracy: 1
time_ms: 450
memory_kb: 24212
final_rank: 8

code_snippet: #include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
const ll INF=1e16;
int main()
{
    int n, m, k; cin>>n>>m>>k;
    ll p[100010], j[100010];
    vector<int> v[100010];
    for(int i=0; i<n; i++) cin>>p[i];
    for(int i=0; i<n; i++){
        int c; cin>>c; c--;
        v[c].push_back(i);
    }
    for(int i=0; i<n; i++) cin>>j[i];
    vector<P> g[100010];
    for(int i=0; i<m; i++){
        int u1, v1; ll t;
        cin>>u1>>v1>>t;
        u1--; v1--;
        g[u1].push_back({t, v1});
        g[v1].push_back({t, u1});
    }
    priority_queue<P, vector<P>, greater<P>> que;
    ll d[2][100010];
    fill(d[0], d[0]+n, INF);
    fill(d[1], d[1]+n, INF);
    ll mx=1e9+7;
    d[0][0]=0;
    que.push({0, 0});
    while(!que.empty()){
        P pr=que.top();
        que.pop();
        int x=pr.second%n;
        int r=pr.second/n;
        if(d[r][x]<pr.first) continue;
        if(r==0){
            if(d[1][x]>d[0][x]+mx-p[x]){
                d[1][x]=d[0][x]+mx-p[x];
                que.push({d[1][x], x+n});
            }
        }
        for(auto q:g[x]){
            int y=q.second;
            if(d[r][y]>d[r][x]+q.first){
                d[r][y]=d[r][x]+q.first;
                que.push({d[r][y], r*n+y});
            }
        }
    }
    for(int i=0; i<k; i++){
        ll ans=-INF;
        for(auto x:v[i]){
            ans=max(ans, -d[1][x]-d[0][x]+mx+j[x]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 370
memory_kb: 26556
final_rank: 9

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
using CostType = long long;
struct Edge {
  int src, dst; CostType cost;
  Edge(int src, int dst, CostType cost = 0) : src(src), dst(dst), cost(cost) {}
  inline bool operator<(const Edge &rhs) const {
    return cost != rhs.cost ? cost < rhs.cost : dst != rhs.dst ? dst < rhs.dst : src < rhs.src;
  }
  inline bool operator<=(const Edge &rhs) const { return cost <= rhs.cost; }
  inline bool operator>(const Edge &rhs) const {
    return cost != rhs.cost ? cost > rhs.cost : dst != rhs.dst ? dst > rhs.dst : src > rhs.src;
  }
  inline bool operator>=(const Edge &rhs) const { return cost >= rhs.cost; }
};

long long p[100000];

struct Dijkstra {
  using Pci = pair<CostType, int>;

  Dijkstra(const vector<vector<Edge> > &graph, const CostType CINF = LINF) : graph(graph), CINF(CINF) {}

  vector<CostType> build(int s) {
    int n = graph.size();
    vector<CostType> dist(n, CINF);
    dist[s] = 0;
    prev.assign(n, -1);
    priority_queue<Pci, vector<Pci>, greater<Pci> > que;
    que.emplace(0, s);
    while (!que.empty()) {
      Pci pr = que.top(); que.pop();
      int ver = pr.second;
      if (dist[ver] < pr.first) continue;
      for (Edge e : graph[ver]) {
        if (dist[e.dst] > dist[ver] + e.cost) {
          dist[e.dst] = dist[ver] + e.cost;
          prev[e.dst] = ver;
          que.emplace(dist[e.dst], e.dst);
        }
      }
    }
    return dist;
  }

  using Pcii = pair<CostType, pair<int, int> >;

  vector<vector<CostType> > build2(int s) {
    int n = graph.size();
    vector<vector<CostType> > dist(n, vector<CostType>(2, CINF));
    dist[s][0] = 0;
    dist[s][1] = INF - p[0];
    priority_queue<Pcii, vector<Pcii>, greater<Pcii> > que;
    que.emplace(dist[s][0], make_pair(s, 0));
    que.emplace(dist[s][1], make_pair(s, 1));
    while (!que.empty()) {
      Pcii pr = que.top(); que.pop();
      int ver = pr.second.first, ate = pr.second.second;
      if (dist[ver][ate] < pr.first) continue;
      for (Edge e : graph[ver]) {
        if (dist[e.dst][ate] > dist[ver][ate] + e.cost) {
          dist[e.dst][ate] = dist[ver][ate] + e.cost;
          que.emplace(dist[e.dst][ate], make_pair(e.dst, ate));
        }
        if (ate == 0) {
          if (dist[e.dst][1] > dist[ver][ate] + e.cost + INF - p[e.dst]) {
            dist[e.dst][1] = dist[ver][ate] + e.cost + INF - p[e.dst];
            que.emplace(dist[e.dst][1], make_pair(e.dst, 1));
          }
        }
      }
    }
    return dist;
  }

  vector<int> build_path(int t) {
    vector<int> res;
    for (; t != -1; t = prev[t]) res.emplace_back(t);
    reverse(ALL(res));
    return res;
  }

private:
  vector<vector<Edge> > graph;
  const CostType CINF;
  vector<int> prev;
};

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m, k; cin >> n >> m >> k;
  vector<long long> j(n);
  vector<int> c(n);
  REP(i, n) cin >> p[i];
  REP(i, n) {
    cin >> c[i]; --c[i];
  }
  REP(i, n) cin >> j[i];
  vector<vector<Edge> > graph(n);
  while (m--) {
    int u, v, t; cin >> u >> v >> t; --u; --v;
    graph[u].emplace_back(Edge(u, v, t));
    graph[v].emplace_back(Edge(v, u, t));
  }
  Dijkstra dij(graph);
  vector<long long> dist = dij.build(0);
  REP(i, n) j[i] -= dist[i];
  vector<vector<long long> > dist2 = dij.build2(0);
  vector<long long> ans(k, -LINF);
  REP(i, n) ans[c[i]] = max(ans[c[i]], j[i] - (dist2[i][1] - INF));
  REP(i, k) cout << ans[i] << '\n';
  return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 36988
final_rank: 13

code_snippet: /* Aa^~ kokoro ga pyonpyon suru n jaa^~
// ZZZXXkXkkkZ!``` ``` ``` ``` ``` ``` ``` ``` ``` ``` ``` ```?Wfpppbpbbpbbpbbbkbkk
// ppbbbpbbpVr`` `` ` ` ` ` ```` `` ` ` ``  ` ` ` ` ` ` ` ` `  dppbbkkkkkkkkkkqkqkk
// HkqqqqqkkWr`` ` ` ``` ``` `?G, ` ` ``.JC!```` ` ` `` `` ````(Wpbkkkkkkkkqkkkkkqk
// mmmmmqqqqpr` `` `` ```````.+zT=`` `` 7TO-.```````` `` `` ```(yppbkkkkkkkkkkkkkkk
// ggmgmmqqqH$ ``````````....````` `  ````````.`````` `` ``````.yfpppbbbbkkkkqqqqqH
// gmmmmmqqqkW<```` `````...`````  .,.`  ````....````` ``````` (Wbqqmgmmgmggggggggg
// qmmmqqqqkkWk.``````````````````` ;:<`` `````.`````````````-_<-?WHHqmmmmmmgmmgggg
// @@@@@@@gggHH6- ``````````````` `` _ `` ```````````````` ._~~_.`-?Wkqmmmmmmmggg@g
// @@@@g@gggHY~.-<_- `````````````````````````````````` ._~~(<-``.`.(WHqqqmmggggmmm
// @@g@gggHH=.`..._<-___..```````````````````````. .-_~~~_(!``-.``.`` OHHWUWHmqHWXW
// gggggmqK1.``..~.. _<<+-(____..  ````````  ..__~~_((<<!.`.``` .``.`` j0C1XUHmHIdW
// ggmmqH0!,_``.>`````` _<<;<v<<<++((((((((((<<<<<<~_. (-.``~``.>..```  jOuWHHqHIdH
// gmmqkW!`(_ J>`    `` ` _~<`_~~~~<<<<<<<~~__````````` ?1. ._`(__```    zXWHg@HkXH
// gHHWS{``(lJ<!``.``.```(:+>`._`````.` <..`` - ``. `   _ ?&._.I`_`````` .XyVfppppW
// HHHSv``.(X:_..... _..(;+<!.(<..-.....-.-_..+_`..<.`.`..`_IJd}  .`..````jqg@@@@@@
// XHWZ{..<Jk~!.`.. (<.-(+>(_.(1.(_..`.`.`.<_.+<_..<<-..._..-zy>.`_`...```.WH@HHHHH
// bkWt~.-jCz(_..`.(+<.(;< ._-<=_(<_..-....(_.<1<..(<<.`._..-JUS-._.`...```dHmH9VUH
// WUUO..(f.(c...__+z<-(+~` _-+<_(><..__.`.(<._.z_.(1;_..__.(C(zT-(..`...``(WHR<+Xk
// kkkk._(_.->..._(z;:_><.._>_+_<(1>_._<...(v<<.(<.(+z<..-_(Z~_<_j+_..`...`(WHKz1ZW
// @@gR._+_..~..-<+z<<?<>```_.<_.(+1><_;_..(1_:`.<<??1z--(+Z!..<_.j<....`..(bgHAAQX
// @@mR.(j:..~.._<z!`.(>~``` ~(_.(+<1><><_.(((_`.<__`.<_.(X>...<_.(<.....`.JUWWWyWW
// @gmH_(zl..(.._+>```<+_````.~>``(+.<?>>_._(<```(<<``(__<>....<.._<.......dXkkkHHH
// mmqHl(dk_.(_.-=~`.`.1-..._~-1.``_:`(??<_~(`.--.&_.`.<(;<...._.._<..`..._Xg@@@@@@
// qHkpk(dX<.(;..j_```.(((JJ&a&-~``````.1<_```-(((e+.-(/`(>...._..(<......(Wmggg@@g
// HVHbWcz><__+_.(_.(dWWHHH@HHc~````````.+~`` (jHMMMHHHm&.?..._<..(<_..._.(WqqHHmHg
// 0>vWWkzZwl~<o.__`__~X@@HM@Hb ```.`.``. ```` d@@HHH@@K?76...(<..(<_...(_(ppWWWWHq
// X0XWHKXXw$<(z<.( `` WHHMHHHH_``````````````.WHHMNMHHH_`(...(<_.(z_..._<(fWVC174W
// XuXWHHWWz>__+z+.!`..??CZYCOX_`````````````.`~.OvTUZUS_`~.._+?_.(_~_.._zjO=1+~+jy
// kkkkkkkkX:._<z=1(_`` << ``->``.``.``.``.```` ?<`` (v!`._..(??_.(1._.._=dUOOzzzwX
// @@@@@@@@H<...1O=v<_...__ -_````````````````.`` `` ~.`` :.~+=?~.(;_(...jdQQQQQkkk
// H@@@@@@@H~...(==>.~~~~~....`.`````````.`````.`........->.(===~~<<.(...(dg@@@@@@@
// @@@H@@HHH_.__(=l>~.~~~~~....``.``.``.```..`......~~~~~(<_+=l=~_<.->..~_dqggggg@g
// @H@@@@MHH_._<(=l>...........```````````````.`...~~~~~~+<(=lz=~((j=z_..~jWqmmgggm
// @@H@@HHWH_._<(lll-.......```.````.``.`..`````........_z<+llZz~(lOO=<...(VYUUUW9Y
// @@HMMHWZf>~_=:=llw+.`````````.`.```__~~_``.`````.....(z+llOOz_zllOlz~..~<<1+dW>_
// MMM#MHHWXl~_=>1ltwOl&.`.``.`````.``````````````.````.(llttwtz(OltwOz<..__zwOwwOz
// HM#HMHUUI<._1z+ttOZttlt&....``.``.`.````.``...``...(zZtttOktzjttttwlz_._<(Xkkkkk
// HHHmHSZu:(_~+OztttXtttOZZttO+-..............-(+ztOttwttttd0tOZttttwOl<~.(_dMMHHH
// rvuuXuuI~~<~(uttttwvOwwwkQQHMMHHHHHHHHHMMMNmgey?OwwwrtttwXOtwttttttXtO-~.((wZyyy
// HHHHHHK>(~(-(dOrtrrl(QgMHMMMHHHHHHHHHHHHHHHH##HMNkX0rrrrXXrd%`` (Ctwwtz_~.<(Wg@H
// NNNNNHD(~(zo~zXrrrQdHHMMNMHHHHHHHHHHHHHHHHHHHHHH##HNmyrdKkwZ ` _``-zwrt1~~_<(MNM
// MMMMM#<<_jwr:(Z4QHHMMHMHHHHHHHHHHHHHHHHHHHHHHHHHHHH###NHSXZ>` ~````.OXtt>~._<?MM
*/

#include <bits/stdc++.h>
using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cout << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}

#ifdef PYONPOI
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cout<<endl; \
  }while(0)
#else
#define DEBUG
#endif


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const LL INF = 1e18;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M, K;
  cin >> N >> M >> K;
  VL pan(N), kind(N), jam(N);
  cin >> pan >> kind >> jam;

  vector<vector<PLL>> G(N);
  REP(i,M){
    LL u, v, t;
    cin >> u >> v >> t;
    --u;
    --v;
    G[u].EB(v, t);
    G[v].EB(u, t);
  }

  const LL BIAS = 1e9;
  VVL dist_pj(N, VL(2, INF));
  {
    // (dist, (vert, flag))
    using S = pair<LL,PII>;
    priority_queue<S,vector<S>,greater<S>> pq;
    pq.push(MP(0, MP(0, 0)));
    dist_pj[0][0] = 0;
    while(!pq.empty()){
      auto s = pq.top();
      pq.pop();

      LL d = s.FF;
      int from = s.SS.FF;
      int flag = s.SS.SS;
      if(dist_pj[from][flag] < d) continue;

      if(flag == 0){
        LL nd = dist_pj[from][flag] + BIAS - pan[from];
        if(dist_pj[from][1] > nd){
          dist_pj[from][1] = nd;
          pq.push(MP(nd, MP(from, 1)));
        }
      }
      for(auto e: G[from]){
        LL nd = d + e.SS;
        int to = e.FF;
        if(dist_pj[to][flag] > nd){
          dist_pj[to][flag] = nd;
          pq.push(MP(nd, MP(to, flag)));
        }  
      }
    }
  }

  VL dist_p(N, INF);
  {
    using S = pair<LL,PII>;
    priority_queue<S,vector<S>,greater<S>> pq;
    pq.push(MP(0, MP(0, 0)));
    dist_p[0] = 0;
    while(!pq.empty()){
      auto s = pq.top();
      pq.pop();

      LL d = s.FF;
      int from = s.SS.FF;
      if(dist_p[from] < d) continue;

      for(auto e: G[from]){
        LL nd = d + e.SS;
        int to = e.FF;
        if(dist_p[to] > nd){
          dist_p[to] = nd;
          pq.push(MP(nd, MP(to, 0)));
        }  
      }
    }
  }

  VL ans(K, -INF);
  REP(i,N){
    int k = kind[i] - 1;
    maxi(ans[k], jam[i] - dist_p[i] - dist_pj[i][1] + BIAS);
  }

  for(auto x : ans) cout << x << endl;

  return 0;
}
accuracy: 1
time_ms: 260
memory_kb: 24864
final_rank: 7

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll ans[100100],jm[100100],dist[2][225816];
int c[100100];
vector<P> g[225816];
priority_queue<P, vector<P>, greater<P> > pq;

int main(void){
	int n,m,k,i,j,u,v;
	ll p,t;
	fill(ans,ans+100100,-INFLL);
	fill(dist[0],dist[2],INFLL);
	cin >> n >> m >> k;
	for(i=0; i<n; ++i){
		cin >> p;
		g[i+n].push_back(P(MOD-p,i));
	}
	for(i=0; i<n; ++i){
		cin >> c[i]; --c[i];
	}
	for(i=0; i<n; ++i){
		cin >> jm[i];
	}
	for(i=0; i<m; ++i){
		cin >> u >> v >> t;
		--u; --v;
		g[u].push_back(P(t,v));
		g[v].push_back(P(t,u));
		g[u+n].push_back(P(t,v+n));
		g[v+n].push_back(P(t,u+n));
	}
	for(j=0; j<2; ++j){
		dist[j][n*j] = 0ll;
		pq.push(P(dist[j][n*j],n*j));
		while(!pq.empty()){
			u = pq.top().second;
			t = pq.top().first;
			pq.pop();
			if(t > dist[j][u]){
				continue;
			}
			for(i=(g[u].l_ength()-1); i>=0; --i){
				v = g[u][i].second;
				t = g[u][i].first;
				if(dist[j][v] > dist[j][u] + t){
					dist[j][v] = dist[j][u] + t;
					pq.push(P(dist[j][v],v));
				}
			}
		}
	}
	for(i=0; i<n; ++i){
		ans[c[i]] = max(ans[c[i]],jm[i]+MOD-dist[0][i]-dist[1][i]);
	}
	for(i=0; i<k; ++i){
		cout << ans[i] << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 460
memory_kb: 38244
final_rank: 17

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll ans[100100],jm[100100],dist[2][100100];
int c[100100];
vector<P> g[225816];
priority_queue<P, vector<P>, greater<P> > pq;

int main(void){
	int n,m,k,i,j,u,v;
	ll p,t;
	fill(ans,ans+100100,-INFLL);
	fill(dist[0],dist[2],INFLL);
	cin >> n >> m >> k;
	for(i=0; i<n; ++i){
		cin >> p;
		g[i].push_back(P(MOD-p,i+n));
		g[i+n].push_back(P(MOD-p,i));
	}
	for(i=0; i<n; ++i){
		cin >> c[i]; --c[i];
	}
	for(i=0; i<n; ++i){
		cin >> jm[i];
	}
	for(i=0; i<m; ++i){
		cin >> u >> v >> t;
		--u; --v;
		g[u].push_back(P(t,v));
		g[v].push_back(P(t,u));
		g[u+n].push_back(P(t,v+n));
		g[v+n].push_back(P(t,u+n));
	}
	for(j=0; j<2; ++j){
		dist[j][n*j] = 0ll;
		pq.push(P(dist[j][n*j],n*j));
		while(!pq.empty()){
			u = pq.top().second;
			t = pq.top().first;
			pq.pop();
			if(t > dist[j][u]){
				continue;
			}
			for(i=(g[u].l_ength()-1); i>=0; --i){
				v = g[u][i].second;
				t = g[u][i].first;
				if(j==0 && u == v+n){
					continue;
				}
				if(j==1 && u+n == v){
					continue;
				}
				if(dist[j][v] > dist[j][u] + t){
					dist[j][v] = dist[j][u] + t;
					pq.push(P(dist[j][v],v));
				}
			}
		}
	}
	for(i=0; i<n; ++i){
		ans[c[i]] = max(ans[c[i]],jm[i]+MOD-dist[0][i]-dist[1][i]);
		ans[c[i]] = max(ans[c[i]],jm[i]+MOD-dist[0][i+n]-dist[1][i+n]);
	}
	for(i=0; i<k; ++i){
		cout << ans[i] << endl;
	}
	return 0;
}
accuracy: 0.29545454545454547
time_ms: 240
memory_kb: 28076
final_rank: 20

code_snippet: #include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
struct edge {
    ll to, cst;
    bool operator<(const edge &e) const { return cst < e.cst; }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, k;
    cin >> n >> m >> k;
    vector<ll> p(n), c(n), j(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        --c[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> j[i];
    }
    vector<vector<edge>> G(n);
    for (int i = 0; i < m; i++) {
        int u, v, t;
        cin >> u >> v >> t;
        --u;
        --v;
        G[u].emplace_back(edge{v, t});
        G[v].emplace_back(edge{u, t});
    }
    priority_queue<P, vector<P>, greater<P>> q;
    vector<ll> d1(n, LINF), dp(n);
    d1[0] = 0;
    q.push(P(0, 0));
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        int v = p.second;
        if (d1[v] < p.first) {
            continue;
        }
        for (auto &e : G[v]) {
            if (chmin(d1[e.to], d1[v] + e.cst)) {
                q.push(P(d1[e.to], e.to));
            }
        }
    }
    for (int i = 0; i < n; i++) {
        dp[i] = d1[i] - p[i];
        q.push(P(dp[i], i));
    }
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        int v = p.second;
        if (dp[v] < p.first) {
            continue;
        }
        for (auto &e : G[v]) {
            if (chmin(dp[e.to], dp[v] + e.cst)) {
                q.push(P(dp[e.to], e.to));
            }
        }
    }
    vector<ll> res(k, -LINF);
    for (int i = 0; i < n; i++) {
        chmax(res[c[i]], j[i] - d1[i] - dp[i]);
    }
    for (int i = 0; i < k; i++) {
        cout << res[i] << endl;
    }
}
accuracy: 1
time_ms: 210
memory_kb: 21556
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cout<<#x<<": "<<(x)<<endl

int n,m,k;
int p[125252];
int c[125252];
int j[125252];

vl dijkstra(vector<vector<pll>> &g, int s){
	int n = g.size();
	vl dist(n,1ll<<60);
	priority_queue<pll> Q;
	dist[s] = 0;
	Q.push(pll(-0,s));
	while(Q.size()){
		pll P = Q.top(); Q.pop();
		int p = P.second;
		if(dist[p] != -P.first)continue;
		for(pll PP : g[p]){
			int to = PP.first;
			ll cost = PP.second;
			ll nd = dist[p] + cost;
			if(nd < dist[to]){
				dist[to] = nd;
				Q.push(pll(-nd,to));
			}
		}
	}
	return dist;
}

int main(){
	scanf("%d%d%d",&n,&m,&k);
	REP(i,n)scanf("%d",p+i);
	REP(i,n)scanf("%d",c+i),c[i]--;
	REP(i,n)scanf("%d",j+i);
	// 0 - i
	vector<vector<pll>> g(n);
	REP(i,m){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		--x;--y;
		g[x].push_back(pll(y,z));
		g[y].push_back(pll(x,z));
	}
	vl dist = dijkstra(g,0);
	// 0 - pan - i
	vector<vector<pll>> g2(n+n);
	REP(i,n)for(pll P : g[i]){
		g2[i].push_back(P);
	}
	REP(i,n){
		g2[i].push_back(pll(i+n,-p[i]));
	}
	vl dist2 = dijkstra(g2,0);
	// (0-pan-) i - jam (-0)
	vector<vector<pll>> g3(1+n+k);
	REP(i,n)for(pll P : g[i]){
		g3[i].push_back(P);
	}
	REP(i,n){
		g3[n+k].push_back(pll(i,dist2[i+n]));
		g3[i].push_back(pll(n+c[i],-j[i]+dist[i]));
	}
	vl dist3 = dijkstra(g3,n+k);
	// output
	REP(i,k){
		printf("%lld\n",-dist3[n+i]);
	}
	return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 57348
final_rank: 18

code_snippet: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<LP> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

struct edge {
	int to; ll cost;
};
vector<edge> G[1 << 17];

void solve() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<ll> p(n), c(n), v(n);
	rep(i, n)cin >> p[i];
	rep(i, n)cin >> c[i];
	rep(i, n)cin >> v[i];
	rep(i, m) {
		int a, b; ll c; cin >> a >> b >> c; a--; b--;
		G[a].push_back({ b,c });
		G[b].push_back({ a,c });
	}
	vector<ll> dist(n, INF);
	dist[0] = 0;
	priority_queue<LP, vector<LP>, greater<LP>> q;
	q.push({ 0,0 });
	while (!q.empty()) {
		LP p = q.top(); q.pop();
		int id = p.second;
		if (p.first > dist[id])continue;
		rep(j, G[id].size()) {
			int to = G[id][j].to;
			ll nd = p.first + G[id][j].cost;
			if (nd < dist[to]) {
				dist[to] = nd;
				q.push({ nd,to });
			}
		}
	}
	vector<ll> val(n);
	priority_queue<LP> que;
	rep(i, n) {
		val[i] = p[i] - dist[i];
		//cout << i << " " << val[i] << endl;
		que.push({ val[i],i });
	}
	while (!que.empty()) {
		LP p = que.top(); que.pop();
		int id = p.second;
		if (p.first < val[id])continue;
		rep(j, G[id].size()) {
			int to = G[id][j].to;
			ll nd = p.first - G[id][j].cost;
			if (nd > val[to]) {
				val[to] = nd;
				que.push({ nd,to });
			}
		}
	}
	//cout << val[0] << endl;
	vector<ll> ans(k, -INF);
	rep(i, n) {
		ans[c[i] - 1] = max(ans[c[i]-1],v[i] - dist[i] + val[i]);
	}
	rep(i, k) {
		cout << ans[i] << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	//cout << fixed << setprecision(10);
	//init();
	solve();
	//stop
	return 0;
}
accuracy: 1
time_ms: 220
memory_kb: 23156
final_rank: 4

code_snippet: #include <bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
#pragma GCC target("avx2")
// #pragma GCC optimize("unroll-loops")

using namespace std;

using i64 = int64_t;

const i64 MOD = (i64)1e9 + 7;

const i64 INF = (i64)1e18 + 7;


template <typename T = i64>
struct Range{
    struct iterator{
        T value;
        const T step, last;
        const T& operator*(){return value;}
        iterator(T value, T step, T last) :
            value(step < static_cast<T>(0) ? max(last, value) : min(last, value)),
            step(step),
            last(last)
        {
        }
        iterator operator++(){value = step < static_cast<T>(0) ? max(value + step, last) : min(value + step, last); return *this;}
        bool operator!=(const iterator& x){return value != x.value;}
    };
    const T start, last, step;

    Range(const T start, const T last, const T step = static_cast<T>(1)) :
        start(start),
        last(last),
        step(step)
    {
    }

    Range(const T last) :
        start(0),
        last(last),
        step(1)
    {
    }

    iterator begin(){return iterator(start, step, last);}
    iterator end(){return iterator(last, step, last);}
};

template <typename F>
struct FixPoint{
    const F _f;
    FixPoint(F&& f) : _f(forward<F>(f)){}

    template<typename... Types>
    decltype(auto) operator()(Types&&... args) const{
        return _f(*this, forward<Types>(args)...);
    }
};

template <typename F>
static decltype(auto) makeRec(F&& f){
    return FixPoint<F>(forward<F>(f));
}

template <typename T, T Value = T()>
vector<T> makeVector(size_t x){
    return vector<T>(x, T(Value));
}

template <typename T, T Value = T(), typename... Types>
auto makeVector(size_t x, Types... args){
    return vector<decltype(makeVector<T, Value>(args...))>(x, makeVector<T, Value>(args...));
}

template <typename T = i64>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template <typename T = i64>
bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}

#ifdef TEST
#define dump(x) fprintf(stderr, "line =%4d, name =%7s , ", __LINE__, #x); cout << "value = " << x << endl;
#define vecdump(x) fprintf(stderr, "line =%4d, name =%7s\n", __LINE__, #x); _dump_macro(x);
#else
#define vecdump(x)
#define dump(x)
#endif


void _dump(int, string& x){
#ifdef TEST
    cout << x << endl;
#endif
}

template <typename T>
void _dump(bool, T& x){
#ifdef TEST
    cout << x << " ";
#endif
}

template <typename T, typename U = typename T::iterator>
void _dump(int, T& x){
#ifdef TEST
    for(auto& elm : x)
        _dump(0, elm);

    cout << endl;
#endif
}

template <typename T>
void _dump_macro(T& x){
    _dump(0, x);
}

void _input(int, string& x){
    cin >> x;
}

template <typename T>
void _input(bool, T& x){
    cin >> x;
}

template <typename T, typename U = typename T::iterator>
void _input(int, T& x){

    for(auto& elm : x)
        _input(0, elm);
}

template <typename T>
void input_single(T& x){
    _input(0, x);
}

auto input(){}

template <typename T, typename... Types>
void input(T& value, Types&&... args){
    input_single(value);
    input(forward<Types>(args)...);
};

void _pararell_input(size_t){}

template <typename T, typename... Types>
void _pararell_input(size_t index, T& value, Types&&... args){
    input(value[index]);
    _pararell_input(index, forward<Types>(args)...);
}

template <typename... Types>
void pararell_input(size_t count, Types&&... args){
    for(const auto& i : Range<>(count))
        _pararell_input(i, forward<Types>(args)...);
}


i64 solve(){

    int n, m, k;
    scanf("%d %d %d", &n, &m, &k);

    vector<i64> p(n), c(n), j(n);
    for(int i = 0; i < n; ++i)
        scanf("%ld", &p[i]);
    for(int i = 0; i < n; ++i){
        scanf("%ld", &c[i]);
        --c[i];
    }
    for(int i = 0; i < n; ++i)
        scanf("%ld", &j[i]);
    vector<vector<pair<i64,i64>>> edges(n);
    for(int i = 0; i < m; ++i){
        int u, v, t;
        scanf("%d %d %d", &u, &v, &t);
        --u, --v;
        edges[u].emplace_back(v, t);
        edges[v].emplace_back(u, t);
    }

    priority_queue<pair<i64,i64>,vector<pair<i64,i64>>,greater<pair<i64,i64>>> que;
    que.emplace(0, 0);
    vector<i64> r(n, INF);
    r[0] = 0;
    while(!que.empty()){
        int pos = que.top().second;
        que.pop();
        for(auto& ed_p : edges[pos])
            if(chmin(r[ed_p.first], r[pos] + ed_p.second))
                que.emplace(r[ed_p.first], ed_p.first);
    }
    vector<i64> r_(n + 1, INF);
    r_[n] = 0;
    edges.emplace_back();
    for(int i = 0; i < n; ++i){
        edges[n].emplace_back(i, r[i] - p[i]);
    }
    que.emplace(0, n);
    while(!que.empty()){
        int pos = que.top().second;
        que.pop();
        for(auto& ed_p : edges[pos])
            if(chmin(r_[ed_p.first], r_[pos] + ed_p.second))
                que.emplace(r_[ed_p.first], ed_p.first);
    }
    vector<i64> ans(k, -INF);
    for(int i = 0; i < n; ++i){
        chmax(ans[c[i]], j[i] - (r[i] + r_[i]));
    }
    for(auto& x : ans)
        printf("%ld\n", x);

    return 0;

}


signed main(){

    int t = 0;
    solve();
}
accuracy: 1
time_ms: 1930
memory_kb: 24624
final_rank: 19