Problem:
JOI 公園 (JOI Park)
20XX 年に IOI 国で行われるオリンピックに備え，IOI 国にある JOI 公園を整備することになった．JOI公園には
N
個の広場があり，広場には 1 から
N
の番号がついている．広場を繋ぐ
M
本の道があり，道には 1 から
M
の番号がついている．道
i
(1 ≤
i
≤
M
) は広場
A
i
と広場
B
i
を双方向に繋いでおり，長さは
D
i
である．どの広場からどの広場へもいくつかの道を辿って行くことができる．
整備計画では，まず，0 以上の整数
X
を選び，広場 1 からの距離が
X
以下であるような広場 (広場 1 を含む) どうしをすべて相互に地下道で結ぶ．ただし，広場
i
と広場
j
の距離とは，広場
i
から広場
j
に行くときに通る道の長さの和の最小値である．整備計画では地下道の整備コストに関する整数
C
が定まっている．地下道の整備にかかるコストは
C × X
である．
次に，地下道で結ばれた広場どうしを結ぶ道をすべて撤去する．道の撤去にコストはかからない．最後に，撤去されずに残った道をすべて補修する．長さ
d
の道を補修するためにかかるコストは
d
である．整備計画実施前の JOI 公園には地下道はない．JOI 公園の整備にかかるコストの和の最小値を求めよ．
課題
JOI 公園の広場の情報と，地下道の整備コストに関する整数が与えられたとき，JOI 公園の整備にかかる
コストの和の最小値を求めるプログラムを作成せよ．
入力
標準入力から以下のデータを読み込め．
1 行目には，整数
N
,
M
,
C
が空白を区切りとして書かれている．これは，広場が
N
個，道が
M
本あり，地下道の整備コストに関する整数が
C
であることを表す．
続く
M
行のうちの
i
行目 (1 ≤
i
≤
M
) には，整数
A
i
,
B
i
,
D
i
が空白を区切りとして書かれている．これは，道
i
が広場
A
i
と広場
B
i
を繋ぎ，長さが
D
i
であることを表す．
出力
標準出力に，JOI 公園の整備にかかるコストの和の最小値を表す整数を 1 行で出力せよ．
制限
すべての入力データは以下の条件を満たす．
2 ≤
N
≤ 100 000．
1 ≤
M
≤ 200 000．
1 ≤
C
≤ 100 000．
1 ≤
A
i
≤
N
(1 ≤
i
≤
M
)．
1 ≤
B
i
≤
N
(1 ≤
i
≤
M
)．
A
i
≠
B
i
(1 ≤
i
≤
M
)．
(
A
i
,
B
i
) ≠ (
A
j
,
B
j
) および (
A
i
,
B
i
) ≠ (
B
j
,
A
j
) (1 ≤
i
<
j
≤
M
)．
1 ≤
D
i
≤ 100 000 (1 ≤
i
≤
M
)．
与えられる入力データにおいては，どの広場からどの広場へもいくつかの道を辿ることにより行けることが保証されている．
入出力例
入力例 1
5 5 2
2 3 1
3 1 2
2 4 3
1 2 4
2 5 5
出力例 1
14
この入力例では，
X
= 3 として，広場 1 からの距離が 3 以下であるような広場 (広場 1, 広場 2, 広場 3) どうしをすべて相互に地下道で結んだとき，整備にかかるコストの和は 2 × 3 + 3 + 5 = 14 となる．これが最小値である．
入力例 2
5 4 10
1 2 3
2 3 4
3 4 3
4 5 5
出力例 2
15
この入力例では，X = 0 のとき整備にかかるコストの和が最小になる．
入力例 3
6 5 2
1 2 2
1 3 4
1 4 3
1 5 1
1 6 5
出力例 3
10
この入力例では，
X
= 5 としてすべての広場を相互に地下道で結んだとき，整備にかかるコストの和が最小になる．
問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #include<iostream>
#include<queue>
#include<functional>
#include<algorithm>
#include<map>
using namespace std;
map<long long, long long>H;
vector<pair<long long, long long>>x[300000]; long long dist[300000];
long long n, m, a[300000], b[300000], c[300000], D;
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>>Q;
void dijkstra() {
	for (long long i = 0; i < 300000; i++)dist[i] = 999999999999999999LL;
	dist[1] = 0; Q.push(make_pair(0, 1));
	while (!Q.empty()) {
		long long a1 = Q.top().first, a2 = Q.top().second; Q.pop();
		for (long long i = 0; i < x[a2].size(); i++) {
			if (dist[x[a2][i].first] > dist[a2] + x[a2][i].second) {
				dist[x[a2][i].first] = dist[a2] + x[a2][i].second;
				Q.push(make_pair(dist[x[a2][i].first], x[a2][i].first));
			}
		}
	}
}
int main() {
	cin >> n >> m >> D; for (long long i = 0; i < m; i++) { cin >> a[i] >> b[i] >> c[i]; x[a[i]].push_back(make_pair(b[i], c[i])); x[b[i]].push_back(make_pair(a[i], c[i])); }
	dijkstra();
	long long minx = 99999999999999999LL, sum2 = 0;
	for (long long i = 0; i < m; i++)H[max(dist[a[i]], dist[b[i]])] += c[i];
	sort(dist + 1, dist + n + 1); long long maxn = dist[n];
	for (long long i = 0; i < m; i++)sum2 += c[i];

	for (long long j = 1; j <= n; j++) {
		if (dist[j - 1] == dist[j])continue;
		long long i = dist[j];
		sum2 -= H[i];
		minx = min(minx, i*D + sum2);
	}
	cout << minx << endl;
	return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 34572
final_rank: 14

code_snippet: #include <iostream>
#include <string.h>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;

struct E{
	long long int len,cost,oldLen;
	int from,to;
	
	bool operator<(const E& e1)const{
		if(len!=e1.len)return len>e1.len;
		return cost>e1.cost;
	}
};

struct E2{
	int from,to;
	bool operator<(const E2& e2)const{
		if(from!=e2.from)return from<e2.from;
		return to<e2.to;
	}
};

long long int lens[100003];
map<long long int,long long int> memo,memo2;
set<E2> cons2;
bool flag[100003];
map<int,vector<E> > cons;
priority_queue<E> pq;


int main() {
	// your code goes here
	int n,m;
	long long int c1,allSum;
	cin>>n>>m>>c1;
	allSum=0;
	for(int i=0;i<m;i++){
		E e;
		int from;
		long long int to,len;
		cin>>from>>to>>len;
		e.to=to;
		e.len=len;
		e.cost=e.len;
		cons[from].push_back(e);
		e.to=from;
		cons[to].push_back(e);
		allSum+=len;
	}
	for(int i=1;i<=n;i++){
		lens[i]=-1;
	}
	lens[0]=0;
	E e1;
	e1.from=0;
	e1.to=1;
	e1.len=0;
	e1.oldLen=0;
	e1.cost=0;
	pq.push(e1);
	while(pq.size()>0){
		E e1=pq.top();
		pq.pop();
		if(lens[e1.to]==-1){
			lens[e1.to]=e1.len;
			memo[e1.len]+=e1.cost;
			memo2[e1.len]+=e1.cost;
		}else if(e1.oldLen<=lens[e1.to]){
			E2 e2;
			e2.from=e1.from;
			e2.to=e1.to;
			if(cons2.find(e2)!=cons2.end())continue;
			e2.from=e1.to;
			e2.to=e1.from;
			cons2.insert(e2);
			memo2[lens[e1.to]]+=e1.cost;
			
			continue;
		}else{
			continue;
		}
		
		for(auto it=cons[e1.to].begin();it!=cons[e1.to].end();it++){
			E e2=(*it);
			E e1a;
			e1a.from=e1.to;
			e1a.to=e2.to;
			e1a.oldLen=e1.len;
			e1a.len=e1.len+e2.cost;
			e1a.cost=e2.cost;
			pq.push(e1a);
		}
	}
	long long int ans=allSum;
	long long int lenSum=0;
	for(auto it=memo.begin();it!=memo.end();it++){
		//cout<<(*it).first<<" "<<(*it).second<<endl;
		lenSum=(*it).first;
		allSum-=memo2[(*it).first];
		long long int s0=lenSum*c1+allSum;
		if(s0<ans)ans=s0;
		//cout<<"("<<s0<<" "<<lenSum<<" "<<allSum<<")";
		//cout<<(*it).first<<" "<<(*it).second<<endl;
	}
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 480
memory_kb: 49952
final_rank: 17

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

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int N, M, C;
    std::cin >> N >> M >> C;
    std::vector<std::vector<std::tuple<int, int, int>>> g(N);
    for (int i{} ; i < M ; i++) {
        int u, v, w;
        std::cin >> u >> v >> w;
        u--; v--;
        g[u].push_back(std::tuple{ v, w, i });
        g[v].push_back(std::tuple{ u, w, i });
    }
    std::vector<long long> dist(N, (long long)2e18);
    dist[0] = 0;
    using qt = std::pair<long long, int>;
    std::priority_queue<qt, std::vector<qt>, std::greater<qt>> que;
    que.push(std::make_pair(dist[0], 0));
    while (que.size()) {
        auto [d, v]{que.top()};
        que.pop();
        if (dist[v] < d) continue;
        for (auto [x, w, _] : g[v]) if (dist[x] > dist[v] + w) {
            dist[x] = dist[v] + w;
            que.push(std::make_pair(dist[x], x));
        }
    }
    std::vector<int> ord(N);
    std::iota(ord.begin(), ord.end(), 0);
    std::sort(ord.begin(), ord.end(), [&](int i, int j) -> bool { return dist[i] < dist[j]; });
    long long ans{(long long)2e18};
    long long sum{};
    std::vector<bool> used(M);
    for (int i{N} ; i >= 0 ; i--) {
        long long need{i ? dist[ord[i - 1]] : 0LL};
        ans = std::min(ans, (long long)C * need + sum);
        // std::cout << need << ' ' << sum << std::endl;
        if (i) {
            for (auto [_, w, j] : g[ord[i - 1]]) if (!used[j]) {
                used[j] = true;
                sum += w;
            }
        }
    }
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 70
memory_kb: 15580
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

struct edge {
    int to, cost;  // 'to'は接続先の頂点、'cost'はエッジのコストを表します。
};

const int INF = 1 << 30;  // 無限大の代わりに大きな値を設定します。
int n, d[100001];  // 'n'は頂点の数、'd'は各頂点までの最短距離を保持します。
vector<edge> g[100001];  // グラフを隣接リストとして保持します。

void dijkstra() {
    // 優先度付きキューを使用して、最小のコストで処理する頂点を管理します。
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    
    fill(d + 1, d + n + 1, INF);  // 各頂点までの距離を無限大に初期化します。
    d[1] = 0;  // 始点の距離は0です。
    q.push(pair<int, int>(0, 1));  // 始点をキューに追加します。
    
    while (!q.empty()) {
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        
        // 現在の距離が更新済みの距離より大きければスキップします。
        if (d[v] < p.first) {
            continue;
        }
        
        // 隣接する全ての頂点に対して距離を更新します。
        for (const edge &e : g[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                q.push(pair<int, int>(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int m, c;
    long long S = 0;
    cin >> n >> m >> c;
    
    // グラフのエッジ情報を読み込みます。
    for (int i = 0; i < m; ++i) {
        int j, k, l;
        cin >> j >> k >> l;
        g[j].emplace_back(edge{k, l});
        g[k].emplace_back(edge{j, l});
        S += l;
    }
    
    // ダイクストラアルゴリズムを実行します。
    dijkstra();
    
    // 各頂点の最短距離を保持するペアのベクターを作成し、ソートします。
    vector<pair<int, int>> v;
    for (int i = 1; i <= n; ++i) {
        v.emplace_back(d[i], i);
    }
    sort(v.begin(), v.end());
    
    long long x = S;
    long long dS = 0;
    
    // 各頂点に対して、最短距離に基づいて計算します。
    for (int i = 1; i < n; ++i) {
        int a = v[i].second;
        for (const edge &e : g[a]) {
            int b = e.to;
            if (d[b] < d[a]) {
                S -= e.cost;
            } else if (d[b] == d[a]) {
                dS += e.cost;
            }
        }
        if (i == n - 1 || d[a] < v[i + 1].first) {
            S -= (dS / 2);
            dS = 0;
            x = min(x, S + static_cast<long long>(c) * d[a]);
        }
    }
    
    // 最小のコストを出力します。
    cout << x << endl;
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 13620
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
    ll N,M,C;
    cin>>N>>M>>C;
    vector<vector<pair<ll,ll>>> G(N);
    ll LEN=0;
    for(int i=0;i<M;i++){
        ll A,B,D;
        cin>>A>>B>>D;
        A--;B--;
        LEN+=D;
        G[A].push_back({B,D});
        G[B].push_back({A,D});
    }
    vector<ll> dist(N,1e18);
    dist[0]=0;
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> Q;
    vector<bool> seen(N,0);
    Q.push({0,0});
    while(!Q.empty()){
        auto nc=Q.top();
        Q.pop();
        ll n=nc.second;
        ll c=nc.first;
        if(seen[n])continue;
        seen[n]=1;
        for(auto vw:G[n]){
            ll v=vw.first;
            ll w=vw.second;
            if(seen[v])continue;
            if(dist[v]<=c+w)continue;
            dist[v]=c+w;
            Q.push({c+w,v});
        }
    }
    vector<pair<ll,ll>> P(N);
    for(int i=0;i<N;i++){
        P[i]={dist[i],i};
    }
    ll an=1e18;
    set<ll> S;
    sort(P.begin(),P.end());
    for(int i=0;i<N;i++){
        ll n=P[i].second;
        for(auto vw:G[n]){
            ll v=vw.first;
            ll w=vw.second;
            if(S.count(v)){
                LEN-=w;
            }
        }
        S.insert(n);
        if(i==N-1||P[i].first!=P[i+1].first){
            an=min(an,LEN+P[i].first*C);
        }
    }
    cout<<an<<endl;
}
accuracy: 1
time_ms: 230
memory_kb: 23108
final_rank: 13

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    ll a,b,c;
    cin>>a>>b>>c;

    ll s=0;

    vector<pll> adj[a+1];
    for (int i=0; i<b; i++) {
        ll x,y,z;
        cin>>x>>y>>z;
        adj[x].push_back({y,z});
        adj[y].push_back({x,z});
        s+=z;
    }

    priority_queue<pll> pq;
    vector<pll> vi(a+1,{1e18,0});
    bool g[a+1];
    memset(g,0,sizeof(g));
    vi[1]={0,0};
    pq.push({0,1});

    while(!pq.empty()){
        ll cost=-pq.top().first,idx=pq.top().second;
        pq.pop();

        if(vi[idx].first<cost) continue;
        g[idx]=true;

        for(pll u:adj[idx]){
            if(!g[u.first]) vi[u.first].second+=u.second;
            if(vi[u.first].first>cost+u.second){
                vi[u.first].first=cost+u.second;
                pq.push({-vi[u.first].first,u.first});
            }
        }
    }

    sort(vi.begin(), vi.end());
    ll ans=1e18,v=0;
    for(pll u:vi){
        if(u.first==1e18) break;
        v+=u.second;
        ans=min(ans,s-v+c*u.first);
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 80
memory_kb: 18468
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using i32 = int;
using i64 = long long;
const i64 sup = (1LL << 60);

int main() {
    i32 n, m, c; cin >> n >> m >> c;
    vector G(n, vector(0, pair(0, 0LL)));
    map<pair<i32, i32>, i64> mp;
    for (i32 _ = 0 ; _ < m ; _++) {
        i32 a, b, d; cin >> a >> b >> d;
        G[a - 1].emplace_back(b - 1, d);
        G[b - 1].emplace_back(a - 1, d);
        mp[pair(min(a - 1, b - 1), max(a - 1, b - 1))] = d;
    }
    vector dist = [&]() {
        vector ds(n, sup);
        ds[0] = 0LL;
        priority_queue<pair<i64, i32>, vector<pair<i64, i32>>, greater<pair<i64, i32>>> que;
        que.emplace(0LL, 0);
        while (que.size()) {
            auto [d, v] = que.top();
            que.pop();
            if (d > ds[v]) {
                continue;
            }
            for (auto [x, w] : G[v]) {
                if (ds[x] > d + w) {
                    ds[x] = d + w;
                    que.emplace(d + w, x);
                }
            }
        }
        map<i64, vector<i32>> mp;
        for (i32 i = 0 ; i < n ; i++) {
            mp[ds[i]].push_back(i);
        }
        vector res(0, pair(0, vector(0, 0)));
        for (auto [val, arr] : mp) {
            res.emplace_back(val, arr);
        }
        reverse(res.begin(), res.end());
        return res;
    }();
    i64 ans = sup;
    i64 sum = 0LL;
    for (i32 i = 0 ; i < (i32)dist.size() ; i++) {
        ans = min(ans, dist[i].first * (i64)c + sum);
        for (auto v : dist[i].second) {
            for (auto [x, _] : G[v]) {
                auto p = pair(min(x, v), max(x, v));
                if (mp.count(p)) {
                    sum += mp[p];
                    mp.erase(p);
                }
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.7796610169491526
time_ms: 360
memory_kb: 43464
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
typedef long long ll;
//typedef int ll;
typedef pair<ll, ll> P;
const long long INF = 1e17;
template <typename T>
void input_arr(vector<T>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
	}
}
template <typename T, typename Q>
void input_arr(vector<pair<T, Q>>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i].first >> A[i].second;
	}
}
template <typename T>
void input_arr(vector<vector<T>>& A, ll H, ll W) {
	for (ll i = 0; i < H; i++) {
		for (ll j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
}
template<typename T = ll>
struct Edge {
    ll from, to; T cost;
    Edge (ll from, ll to, T cost = 1) : from(from), to(to), cost(cost) {}
};
template<typename T = ll>
struct Graph {
    vector<vector<Edge<T>>> G;
    Graph() = default;
    explicit Graph(ll N) : G(N) {}
    size_t size() const {
        return G.size();
    }
    void add_edge(ll from, ll to, T cost = 1, bool direct = false) {
        G[from].emplace_back(from, to, cost);
        if (!direct) G[to].emplace_back(to, from, cost);
    }
    void read(ll M, ll padding = -1, bool weight = false, bool direct = false) {
        for (ll i = 0; i < M; i++) {
            ll a, b; cin >> a >> b;
            a += padding;
            b += padding;
            T c = T(1);
            if (weight) cin >> c;
            add_edge(a, b, c, direct);
        }
    }
    vector<Edge<T>> &operator[](const int &k) {
        return G[k];
    }
};
void dijkstra(const Graph<long long>& G, int s, vector<long long>& dis) {
    int N = G.size();
    dis.resize(N, INF);
    priority_queue<P, vector<P>, greater<P>> pq;
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {
            continue;
        }
        for (auto& e : G.G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}
void solve() {
    ll N, M, C; cin >> N >> M >> C;
    Graph<ll>G(N);
    vector<P>e(M);
    vector<ll>w(M);
    for (ll i = 0; i < M; i++) {
        ll u, v, c; cin >> u >> v >> c;
        u--; v--;
        G.add_edge(u, v, c, false);
        e[i] = {u, v};
        w[i] = c;
    }
    vector<ll>dist(N, INF);
    dijkstra(G, 0, dist);
    vector<ll>D;
    for (ll i = 0; i < dist.size(); i++) {
        D.push_back(dist[i]);
    }
    sort(D.begin(), D.end());
    vector<ll>A;
    A.push_back(D[0]);
    for (ll i = 1; i < D.size(); i++) {
        if (D[i] != D[i - 1]) A.push_back(D[i]);
    }
    vector<ll>sum(A.size(), 0);
    for (ll i = 0; i < M; i++) {
        ll pos = lower_bound(A.begin(), A.end(), max(dist[e[i].first], dist[e[i].second])) - A.begin();
        sum[pos] += w[i];
    }
    ll ans = INF;
    ll num = 0;
    for (ll i = sum.size() - 1; i >= 0; i--) {
        ans = min(ans, C * A[i] + num);
        num += sum[i];
    }
    ans = min(ans, num);
    cout << ans << endl;
}
int main() {
    ll T=1; //cin >> T;
    while (T--) solve();
}
accuracy: 1
time_ms: 160
memory_kb: 27728
final_rank: 12

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n,m,c);
    vector<vector<pair<int,int>>> g(n);
    int u,v;
    ll w,sumv=0;
    rep(i,m){
        in(u,v,w);
        sumv+=w;
        g[--u].emplace_back(--v,w);
	    g[v].emplace_back(u,w);
    }
    vector<ll> dist(n,INF2);
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
    dist[0]=0;
    pq.push({0,0});
    while(!pq.empty()){
        tie(w,v)=pq.top();
        pq.pop();
        for(auto p:g[v]){
            if(w+p.second>=dist[p.first])continue;
            dist[p.first]=w+p.second;
            pq.push({dist[p.first],p.first});
        }
    }
    auto dist2=dist;
    sort(all(dist2));
    dist2.erase(unique(all(dist2)),dist2.end());
    vector<vector<int>> t(dist2.size());
    ll ans=INF2,cnt=0;
    vector<bool> used(n,false);
    for(int i=0;i<n;i++){
	    dist[i]=lower_bound(all(dist2),dist[i])-dist2.begin();
	    t[dist[i]].push_back(i);
    }
    chmin(ans,sumv);
    for(int i=0;i<t.size();i++){
	    for(auto v:t[i]){
		    cnt++;
            used[v]=true;
	        for(auto p:g[v]){
		        if(used[p.first])sumv-=p.second;
	        }
        }
        chmin(ans,c*dist2[i]+sumv);
    }
    out(ans);
}
accuracy: 1
time_ms: 90
memory_kb: 17696
final_rank: 4

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

using namespace std;
using Int = long long;
constexpr Int inf = 1e18;
class unionfind {
    vector<int> par, rank, size_;
public:
    unionfind(int n) :par(n), rank(n), size_(n, 1) {
        iota(par.begin(),par.end(), 0);
    }
    int find(int x) {
        if (par[x] == x)return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])swap(x, y);
        par[y] = x;
        size_[x] += size_[y];
        if (rank[x] == rank[y])rank[x]++;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return size_[find(x)];
    }
};

int main(){
    Int N,M,C; 
    cin >> N >> M >> C;
    vector<vector<pair<Int,Int>>>edge(N);
    vector<tuple<int,int,int>> input;
    auto uf = unionfind(N + 1);
    int root = N;
    Int ans = inf;
    Int sum = 0;
    for(int i = 0; i < M; ++i) {
        int s,t,c; cin >> s >> t >> c;
        --s; --t;
        edge[s].emplace_back(t,c);
        edge[t].emplace_back(s,c);
        input.emplace_back(s,t,c);
        sum += c;
    }
    ans = min(ans, sum);
    vector<Int>d(N,inf);
    d[0]= 0;
    
    priority_queue<pair<Int,Int>,vector<pair<Int,Int>>,greater<>> que;
    que.emplace(d[0], 0);
    int complete = 0;
    while(not que.empty()){
        auto [dist, cv] = que.top();
        que.pop();
        if(dist > d[cv]) continue;
        // d[cv] is the min disntace from d[0]
        uf.unite(root,cv);

        Int subCost = C * dist;
        for(auto [nv,cost] : edge[cv]){
            if(uf.same(nv,root)){
                sum -= cost;
            } else if (d[nv] > dist + cost) {
                d[nv] = dist + cost;
                que.emplace(d[nv],nv);
            }
        }
        ans = min(ans, sum + subCost);
//        cout << dist << " " << ans << endl;
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 140
memory_kb: 22532
final_rank: 11

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
 
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
 
#define MOD 1000000007
 
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-12, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< 1000000007 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;
 
  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
 
  inline T fact(int k) const { return _fact[k]; }
 
  inline T rfact(int k) const { return _rfact[k]; }
 
  inline T inv(int k) const { return _inv[k]; }
 
  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }
 
  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
 
  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};
 
ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  while(n) {
    if(n&1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
} 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
class UnionFind {
public:
    vector <ll> par; 
    vector <ll> siz; 
 
    vector <ll> maxv;
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
 
    ll root(ll x) { 
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
 
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
 
    bool issame(ll x, ll y) { 
        return root(x) == root(y);
    }
 
    ll size(ll x) { 
        return siz[root(x)];
    }
};

vector<vector<pair<int, int>>> g(101010);
ll d[101010];
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  ll n, m, C; cin >> n >> m >> C;
  vector<int> a(m), b(m), c(m);
  REP(i,m) {
    
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    g[a[i]].push_back({b[i], c[i]});
    g[b[i]].push_back({a[i], c[i]});
    
  }
  REP(i,n) d[i] = (1LL<<60);
  d[0] = 0;
  priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq;
  pq.push({0, 0});
  while(pq.size()) {
    auto[c, v] = pq.top(); pq.pop();
    if(d[v] < c) continue;
    for(auto[u, cost]: g[v]) {
      if(d[u] > d[v] + cost) {
        d[u] = d[v] + cost;
        pq.push({d[u], u});
      }
    }
  }
  priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> q;
  REP(i,n) {
    q.push({d[i], i});
  }
  vector<vector<int>> g(n);
  REP(i,m) {
    int u = a[i], v = b[i];
    if(d[u] > d[v]) {
      g[u].push_back(i);
    }else{
      g[v].push_back(i);
    }
  }
  ll ans = 1LL<<60;
  ll sum = 0;
  REP(i,m) sum += c[i];
  while(q.size()) {
    int idx = q.top().second;
    q.pop();
    for(auto j: g[idx]) {
      sum -= c[j];
    }
    ans = min(ans, d[idx]*C + sum);
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 22188
final_rank: 9

code_snippet: #include <cstdio>
#include <vector>
#include <queue>
#include <functional>
#include <iostream>
#define INF 1e15

typedef long long ll;
typedef std::pair<ll, int> P;
struct Edge {
	int t, id;
	ll d;

	Edge(int tt, int ii, ll dd) {
		t = tt;
		id = ii;
		d = dd;
	}
};

#define min(x,y) (x)>(y)?(y):(x)

int n, m, c;
int a[200001], b[200001], d[200001];
ll cost[100001], x_max;
std::vector<Edge> G[100001];
bool flag[200001];
ll costdata[100001];
int index[100001], datasize;

void dijk()
{
	std::priority_queue<P, std::vector<P>, std::greater<P> > que;
	que.push(P(0, 1));
	for (int i = 1; i <= n; i++)cost[i] = INF;
	cost[1] = 0;
	while (que.size()) {
		P q = que.top();
		que.pop();
		if (q.first != cost[q.second])continue;
		costdata[datasize] = cost[q.second];
		index[datasize++] = q.second;
		//x_max = max(x_max, q.first);
		for (int i = 0; i < G[q.second].size(); i++) {
			Edge e = G[q.second][i];
			if (e.d + q.first < cost[e.t]) {
				cost[e.t] = e.d + q.first;
				que.push(P(cost[e.t], e.t));
			}
		}
	}
	return;

}

int main()
{
	
	scanf("%d %d %d", &n, &m, &c);
	long long  res = INF;
	for (int i = 0; i < m; i++) {
		scanf("%d %d %d", &a[i], &b[i], &d[i]);
		G[a[i]].push_back(Edge(b[i], i, d[i]));
		G[b[i]].push_back(Edge(a[i], i, d[i]));
	}
	dijk();
	long long  alldist = 0;
	for (int i = n - 1; i >= 0; i--) {
		res = min(res, costdata[i] * c + alldist);
		for (int j = 0; j < G[index[i]].size(); j++) {
			Edge e = G[index[i]][j];
			if (!flag[e.id]) {
				flag[e.id] = true;
				alldist += e.d;
			}
		}
	}
	res = min(res, alldist);
	printf("%lld\n", res);
	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 20896
final_rank: 6

code_snippet: #include <cstdio>
#include <vector>
#include <queue>
#include <functional>
#include <iostream>
#define INF 1e15

typedef long long ll;
typedef std::pair<ll, int> P;
struct Edge {
	int t, id;
	ll d;

	Edge(int tt, int ii, ll dd) {
		t = tt;
		id = ii;
		d = dd;
	}
};

int n, m, c;
int a[200001], b[200001], d[200001];
ll cost[100001], x_max;
std::vector<Edge> G[100001];
bool flag[200001];
ll costdata[100001];
int index[100001], datasize;

void dijk()
{
	std::priority_queue<P, std::vector<P>, std::greater<P> > que;
	que.push(P(0, 1));
	for (int i = 1; i <= n; i++)cost[i] = INF;
	cost[1] = 0;
	while (que.size()) {
		P q = que.top();
		que.pop();
		if (q.first != cost[q.second])continue;
		costdata[datasize] = cost[q.second];
		index[datasize++] = q.second;
		//x_max = max(x_max, q.first);
		for (int i = 0; i < G[q.second].size(); i++) {
			Edge e = G[q.second][i];
			if (e.d + q.first < cost[e.t]) {
				cost[e.t] = e.d + q.first;
				que.push(P(cost[e.t], e.t));
			}
		}
	}
	return;

}

int main()
{
	
	scanf("%d %d %d", &n, &m, &c);
	long long  res = INF;
	for (int i = 0; i < m; i++) {
		scanf("%d %d %d", &a[i], &b[i], &d[i]);
		G[a[i]].push_back(Edge(b[i], i, d[i]));
		G[b[i]].push_back(Edge(a[i], i, d[i]));
	}
	dijk();
	long long  alldist = 0;
	for (int i = n - 1; i >= 0; i--) {
		res = std::min(res, costdata[i] * c + alldist);
		for (int j = 0; j < G[index[i]].size(); j++) {
			Edge e = G[index[i]][j];
			if (!flag[e.id]) {
				flag[e.id] = true;
				alldist += e.d;
			}
		}
	}
	res = std::min(res, alldist);
	printf("%lld\n", res);
	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 20900
final_rank: 7

code_snippet: #include <cstdio>
#include <vector>
#include <queue>
#include <functional>
#define INF 1e15
using namespace std;

typedef long long ll;
typedef pair<ll, int> P;
struct edge {
	int t, id;
	ll d;

	edge(int tt, int ii, ll dd) {
		t = tt;
		id = ii;
		d = dd;
	}
};

int n, m, c;
int a[200001], b[200001], d[200001];
ll cost[100001], x_max;
vector<edge> G[100001];
bool flag[200001];
ll costdata[100001];
int index[100001], datasize;


void dijk() {
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0, 1));
	for (int i = 1; i <= n; i++)cost[i] = INF;
	cost[1] = 0;
	while (que.size()) {
		P q = que.top();
		que.pop();
		if (q.first != cost[q.second])continue;
		costdata[datasize] = cost[q.second];
		index[datasize++] = q.second;
		x_max = max(x_max, q.first);
		for (int i = 0; i < G[q.second].size(); i++) {
			edge e = G[q.second][i];
			if (e.d + q.first < cost[e.t]) {
				cost[e.t] = e.d + q.first;
				que.push(P(cost[e.t], e.t));
			}
		}
	}
	return;
}

int main(void) {
	scanf("%d %d %d", &n, &m, &c);
	ll res = INF;
	for (int i = 0; i < m; i++) {
		scanf("%d %d %d", &a[i], &b[i], &d[i]);
		G[a[i]].push_back(edge(b[i], i, d[i]));
		G[b[i]].push_back(edge(a[i], i, d[i]));
	}
	dijk();
	ll alldist = 0;
	for (int i = n - 1; i >= 0; i--) {
		res = min(res, costdata[i] * c + alldist);
		for (int j = 0; j < G[index[i]].size(); j++) {
			edge e = G[index[i]][j];
			if (!flag[e.id]) {
				flag[e.id] = true;
				alldist += e.d;
			}
		}
	}
	res = min(res, alldist);
	printf("%lld\n", res);
	return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 20384
final_rank: 8

code_snippet: #include<bits/stdc++.h>
#define int long long
constexpr long long mod = 1000000007;
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << (x) << "\n"
using namespace std;
int n, m, c, a[234567], b[234567], l[234567], cost[123456];
vector<pair<int, int>>g[123456];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>pq;
set<int>s1; vector<int>v1; map<int, int>m1;
vector<int>vl[123456]; int lsum, ans = 20000010000;
signed main() {
	cin >> n >> m >> c;
	for1(i, m) {
		cin >> a[i] >> b[i] >> l[i];
		g[b[i]].push_back(mp(a[i], l[i]));
		g[a[i]].push_back(mp(b[i], l[i]));
		lsum += l[i];
	}
	for1(i, n)cost[i] = 20000010000; cost[1] = 0; pq.push(mp(0, 1));
	while (pq.size()) {
		int t1 = pq.top().first, x1 = pq.top().second;
		pq.pop();
		if (t1 > cost[x1])continue;
		for (pair<int, int>p1 : g[x1])
			if (t1 + p1.second < cost[p1.first]) {
				cost[p1.first] = t1 + p1.second;
				pq.push(mp(t1 + p1.second, p1.first));
			}
	}
	for1(i, n)s1.insert(cost[i]);
	for (int i : s1)v1.push_back(i);
	for0(i, v1.size())m1[v1[i]] = i;
	for1(i, n)vl[m1[cost[i]]].push_back(i);
	for0(i, v1.size()) {
		for (int j : vl[i]) {
			for (pair<int, int>p1 : g[j]) {
				if (m1[cost[p1.first]] < i)lsum -= p1.second;
				if (m1[cost[p1.first]] == i && p1.first < j)lsum -= p1.second;
			}
		}
		ans = min(ans, c * v1[i] + lsum);
	}
	puts(ans);
}
accuracy: 1
time_ms: 410
memory_kb: 35816
final_rank: 16

code_snippet: #include<bits/stdc++.h>
#define int long long
constexpr long long mod = 1000000007;
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << (x) << "\n"
using namespace std;
int n, m, c, a[234567], b[234567], l[234567], cost[123456];
vector<pair<int, int>>g[123456];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>pq;
set<int>s1; vector<int>v1;
int f(int x) {
	int r = c * x;
	for1(i, m) {
		if (max(cost[a[i]], cost[b[i]]) > x)r += l[i];
	}
	return r;
}
signed main() {
	cin >> n >> m >> c;
	for1(i, m) {
		cin >> a[i] >> b[i] >> l[i];
		g[b[i]].push_back(mp(a[i], l[i]));
		g[a[i]].push_back(mp(b[i], l[i]));
	}
	for1(i, n)cost[i] = 20000010000; cost[1] = 0; pq.push(mp(0, 1));
	while (pq.size()) {
		int t1 = pq.top().first, x1 = pq.top().second;
		pq.pop();
		if (t1 > cost[x1])continue;
		for (pair<int, int>p1 : g[x1]) {
			if (t1 + p1.second < cost[p1.first]) {
				cost[p1.first] = t1 + p1.second;
				pq.push(mp(t1 + p1.second, p1.first));
			}
		}
	}
	for1(i, n)s1.insert(cost[i]);
	for (int i : s1)v1.push_back(i);
	int rd = 0, ld = v1.size() - 1, ans = min({ f(v1[rd]),f(v1[ld]) });
	while (ld - rd > 2) {
		int mid1 = (rd + rd + ld) / 3, mid2 = (rd + ld + ld) / 3;
		int f1 = f(v1[mid1]), f2 = f(v1[mid2]);
		if (f1 < f2)ld = mid2;
		else if (f1 > f2)rd = mid1;
		else {
			ans = min({ ans,f(v1[ld]),f(v1[rd]) });
			ld--; rd++;
		}
	}
	for (int i = rd; i <= ld; i++)ans = min(ans, f(v1[i]));
	puts(ans);
}
accuracy: 0.7288135593220338
time_ms: 210
memory_kb: 25988
final_rank: 20

code_snippet: #include<bits/stdc++.h>
#define int long long
constexpr long long mod = 1000000007;
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << (x) << "\n"
using namespace std;
int n, m, c, a[234567], b[234567], l[234567], cost[123456];
vector<pair<int, int>>g[123456];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>pq;
vector<int>v1;
int f(int x) {
	int r = c * x;
	for1(i, m) {
		if (max(cost[a[i]], cost[b[i]]) > x)r += l[i];
	}
	return r;
}
signed main() {
	cin >> n >> m >> c;
	for1(i, m) {
		cin >> a[i] >> b[i] >> l[i];
		g[b[i]].push_back(mp(a[i], l[i]));
		g[a[i]].push_back(mp(b[i], l[i]));
	}
	for1(i, n)cost[i] = 20000010000; cost[1] = 0; pq.push(mp(0, 1));
	while (pq.size()) {
		int t1 = pq.top().first, x1 = pq.top().second;
		pq.pop();
		if (t1 > cost[x1])continue;
		for (pair<int, int>p1 : g[x1]) {
			if (t1 + p1.second < cost[p1.first]) {
				cost[p1.first] = t1 + p1.second;
				pq.push(mp(t1 + p1.second, p1.first));
			}
		}
	}
	for1(i, n)v1.push_back(cost[i]);
	sort(all(v1)); v1.erase(unique(all(v1)), v1.end());
	int rd = 0, ld = v1.size() - 1, ans = min({ f(v1[rd]),f(v1[ld]) });
	while (ld - rd > 2) {
		int mid1 = (rd + rd + ld) / 3, mid2 = (rd + ld + ld) / 3;
		int f1 = f(v1[mid1]), f2 = f(v1[mid2]);
		if (f1 < f2)ld = mid2;
		else if (f1 > f2)rd = mid1;
		else {
			ans = min({ ans,f(v1[ld]),f(v1[rd]) });
			ld--; rd++;
		}
	}
	for (int i = rd; i <= ld; i++)ans = min(ans, f(v1[i]));
	puts(ans);
}
accuracy: 0.7288135593220338
time_ms: 200
memory_kb: 23280
final_rank: 19

code_snippet: #include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 10000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;

typedef pair <ll, ll> P;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
struct edge { ll to, cost; };

ll d[213456];//始点sから終点tまでのコストd[t]
vector<edge> G[213456];//コスト
void dijkstra(ll s) {
	//greater<P>を指定→firstが小さい順
	priority_queue<P, vector<P>, greater<P> >que;
	fill(d, d + 213456, INF);//←TLE気を付ける
	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));
			}
		}
	}
}
signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	//cout << fixed << setprecision(15);

	//input
	ll n, m, c; cin >> n >> m >> c;
	vector<ll> gs(m), gt(m), gd(m);
	ll sum = 0;
	rep(i, m) {
		cin >> gs[i] >> gt[i] >> gd[i];
		sum += gd[i];
		G[gs[i]].push_back({ gt[i], gd[i] });
		G[gt[i]].push_back({ gs[i], gd[i] });
	}
	//dijkstra
	dijkstra(1);
	//rui
	//まず道の補修をcount
	map<ll, ll> rui;
	rep(i, m) {
		rui[max(d[gs[i]], d[gt[i]])] += gd[i];
	}
	//Dに頂点ごとの最小距離を入れる
	vector<ll> D; map<ll, bool> visit;
	rep2(i, n) { if (visit[d[i]] == false) { D.push_back(d[i]); visit[d[i]] = true; } }
	sort(all(D));
	//そのDでrui
	rep2(i, D.size() - 1) {
		rui[D[i]] += rui[D[i - 1]];
	}
	ll ans = INF;
	rep(i, D.size()) {
		rui[D[i]] = sum - rui[D[i]];
		ans = min(ans, c * D[i] + rui[D[i]]);
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 34072
final_rank: 15

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

using lint = long long;

constexpr lint INF = 1LL << 61;

struct node{
    int id;
    lint cost;

    bool operator<(const node& rhs) const {
        return cost > rhs.cost;
    }
};

struct edge{
    int from, to;
    lint cost;
};

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

int main(){
    int n, m;
    lint c;
    cin >> n >> m >> c;

    vector< vector<edge> > g(n);
    vector<edge> es(m);
    lint d = 0;

    for(edge& e : es){
        cin >> e.from >> e.to >> e.cost;
        --e.from;
        --e.to;

        g[e.from].push_back(e);
        g[e.to].push_back({e.to, e.from, e.cost});

        d += e.cost;
    }

    vector<lint> cost(n, INF);
    cost[0] = 0;
    priority_queue<node> que;
    que.push({0, 0LL});

    while(!que.empty()){
        node now = que.top();
        que.pop();

        if(cost[now.id] < now.cost){
            continue;
        }

        for(auto e : g[now.id]){
            if(chmin(cost[e.to], now.cost + e.cost)){
                que.push({e.to, now.cost + e.cost});
            }
        }
    }

    vector<int> id;
    for(int i = 0 ; i < n ; ++i){
        id.emplace_back(i);
    }

    sort(id.begin(), id.end(), [&](int i, int j){ return cost[i] < cost[j]; });
    sort(es.begin(), es.end(), [&](edge l, edge r){ return max(cost[l.from], cost[l.to]) < max(cost[r.from], cost[r.to]); });

    lint ans = INF;
    int j = 0;

    for(auto i : id){
        while(j < m && max(cost[es[j].from], cost[es[j].to]) <= cost[i]){
            d -= es[j].cost;
            ++j;
        }

        chmin(ans, c * cost[i] + d);
    }

    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 21444
final_rank: 10

code_snippet: #include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const long long inf = 1LL << 62;
struct edge {
	int to, cost;
};
struct state {
	int pos; long long cost;
	bool operator<(const state& s) const {
		return cost > s.cost;
	}
};
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> A(M), B(M), D(M);
	vector<vector<edge> > G(N);
	long long sumdist = 0;
	for (int i = 0; i < M; ++i) {
		cin >> A[i] >> B[i] >> D[i]; --A[i], --B[i];
		G[A[i]].push_back(edge{ B[i], D[i] });
		G[B[i]].push_back(edge{ A[i], D[i] });
		sumdist += D[i];
	}
	vector<long long> dist(N, inf);
	priority_queue<state> que;
	dist[0] = 0;
	que.push(state{ 0, 0 });
	vector<bool> vis(N, false);
	while (!que.empty()) {
		int u = que.top().pos; que.pop();
		if (vis[u]) continue;
		vis[u] = true;
		for (edge e : G[u]) {
			if (dist[e.to] > dist[u] + e.cost) {
				dist[e.to] = dist[u] + e.cost;
				que.push(state{ e.to, dist[e.to] });
			}
		}
	}
	vector<long long> sd = dist;
	sort(sd.begin(), sd.end());
	sd.erase(unique(sd.begin(), sd.end()), sd.end());
	vector<long long> g(sd.size());
	for (int i = 0; i < M; ++i) {
		int ptr = lower_bound(sd.begin(), sd.end(), max(dist[A[i]], dist[B[i]])) - sd.begin();
		g[ptr] += D[i];
	}
	for (int i = 1; i < sd.size(); ++i) {
		g[i] += g[i - 1];
	}
	long long delta = inf;
	for (int i = 0; i < sd.size(); ++i) {
		delta = min(delta, sd[i] * C - g[i]);
	}
	cout << delta + sumdist << endl;
	return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 17004
final_rank: 5