Problem:
テレポート移動網
人類は研究の末、ついにテレポート装置を利用した移動網を構築できるようになった。テレポート装置が設置できるのは$1$から$N$までの番号が付いた地点だけで、全部で$M$台のテレポート装置が設置されている。$i$番目のテレポート装置は地点$a_i$に設置されており、移動先$b_i$と使用コスト$f_i$が設定されている。地点$a_i$にいる利用者は使用コスト$f_i$を支払うと地点$b_i$に移動できる。
テレポート装置の利用者は事前に申請をすれば、装置を他の地点に移設できる。装置１台を１つ離れた番号の地点に移設するごとに申請が１回必要で、１回当たり申請コスト$C$がかかる。申請には以下のルールがある。
１回の申請では、装置1台を移設前の地点から番号が１つだけ離れた地点にだけ移設できる。たとえば、地点7にあるテレポート装置は地点6か8だけに移設できる。また、地点1にある装置は2だけに、地点$N$にある装置は$N-1$だけにそれぞれ移設できる。
装置が移設されても、その装置により利用者が移動できる地点や使用コストは移設前と変わらない。
同じ装置の移設は何度でも申請することができる。
同じ装置の移設を何度も申請することで、２つ以上番号が離れた地点へ移設させることができる。たとえば、地点5にある装置を地点8に移設したいときは、5から6、6から7、7から8への各移設のために３回の申請が必要で、そのために$3 \times C$の申請コストがかかる。
あなたは、テレポート装置を利用して地点$1$から地点$N$まで移動する計画を立てているが、使用コストと申請コストの総和をできるだけ少なくして出費を抑えたいと思っている。
テレポート装置の情報と1回あたりの申請コストが与えられたとき、利用者が地点$1$から地点$N$へテレポートだけで移動するのにかかる、使用コストと装置の移設に必要な申請コストの総和の最小値を求めるプログラムを作成せよ。
入力
入力は以下の形式で与えられる。
$N$ $M$ $C$
$a_1$ $b_1$ $f_1$
$a_2$ $b_2$ $f_2$
:
$a_M$ $b_M$ $f_M$
１行目に、地点の数$N$ ($2 \leq N \leq 200,000$)、テレポート装置の数$M$ ($1 \leq M \leq 100,000$)、１回あたりの申請コスト$C$ ($1 \leq C \leq 1,000$)が与えられる。続く$M$行に、$i$番目のテレポート装置が設置されている地点の番号$a_i$ ($1 \leq a_i \leq N$)、転送先の地点の番号$b_i$ ($1 \leq b_i \leq N$)、使用コスト$f_i$ ($1 \leq f_i \leq 1,000$)が与えられる。入力はすべて整数である。
出力
コストの総和の最小値を１行に出力する。ただし、どのようにしてもたどり着けない場合は、-1を出力する。
入出力例
入力例１
9 2 3
3 6 1
5 9 7
出力例１
17
入力例２
3 3 1
3 1 1
3 2 1
1 2 1
出力例２
-1
入力例３
10 4 1
1 9 1
5 10 1
9 5 3
10 5 1
出力例３
4
申請コスト１を使って地点１０にあるテレポート装置を地点９に移設することで、利用者は地点１から地点１０へ使用コスト３で移動することができるので、コストの総和の最小値は４になる。

Submitted solutions:

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

constexpr int BIG_INT = 1'000'000'100;
constexpr long BIG_LONG = 1'000'000'000'000'000'100;

template <typename T>
using rev_pq = priority_queue<T, vector<T>, greater<T>>;

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

    int n, m, c;
    cin >> n >> m >> c;
    // to, cos
    vector g(n, vector(0, make_pair(0, 0)));
    for (int i = 0; i < m; i++) {
        int a, b, f;
        cin >> a >> b >> f;
        a--, b--;
        g[b].push_back({a, f});
    }

    vector<int> dist(n, BIG_INT);
    dist[n - 1] = BIG_INT;
    rev_pq<pair<int, int>> pq;
    pq.push({-1, n - 1});
    while (!pq.empty()) {
        auto [co, now] = pq.top();
        pq.pop();
        if (co == -1) {
            co = 0;
        } else if (dist[now] != co)
            continue;

        for (auto [nex, cos] : g[now]) {
            for (int i = nex; i >= 0; i--) {
                int tmp = co + cos + c * (nex - i);
                if (dist[i] > tmp) {
                    dist[i] = tmp;
                    pq.push({tmp, i});
                } else {
                    break;
                }
            }
            for (int i = nex + 1; i < n; i++) {
                int tmp = co + cos + c * (i - nex);
                if (dist[i] > tmp) {
                    dist[i] = tmp;
                    pq.push({tmp, i});
                } else {
                    break;
                }
            }
        }
    }
    cout << (dist[0] == BIG_INT ? -1 : dist[0]) << endl;
}
accuracy: 1
time_ms: 290
memory_kb: 44536
final_rank: 20

code_snippet: #include<iostream>
#include<vector>
#include<queue>
#include<array>
using namespace std;
int main()
{
  int n,m,c;
  cin >> n >> m >> c;
  vector<vector<pair<int,int>>>graph(n);
  for(int i=0;i<m;i++){
    int a,b,f;
    cin >> a >> b >> f;
    a--;
    b--;
    graph[a].push_back(make_pair(b,f));
  }

  vector<pair<long long,long long>>dist(n,make_pair(1e18,1e18));
  dist[0]=make_pair(0,0);

  priority_queue<array<long long,3>,vector<array<long long,3>>,greater<array<long long,3>>>pq;
  pq.push({0,0,0});

  while(pq.size()){
    array<long long,3>hako=pq.top();
    pq.pop();

    int a=hako[1],b=hako[2];
    if(b==0 && dist[a].first!=hako[0])continue;
    else if(b==1 && dist[a].second!=hako[0])continue;

    long long cost;
    if(b==0)cost=dist[a].first;
    else cost=dist[a].second;

    for(int i=0;i<graph[a].size();i++)if(dist[graph[a][i].first].first>cost+graph[a][i].second){
	dist[graph[a][i].first].first=cost+graph[a][i].second;
	pq.push({dist[graph[a][i].first].first,graph[a][i].first,0});
      }

    if(a-1>=0 && dist[a-1].second>cost+c){
      dist[a-1].second=cost+c;
      pq.push({dist[a-1].second,a-1,1});
    }
    if(a+1<n && dist[a+1].second>cost+c){
      dist[a+1].second=cost+c;
      pq.push({dist[a+1].second,a+1,1});
    }
  }

  long long ans=dist[n-1].first;
  if(ans==1e18)cout << -1 << endl;
  else cout << ans << endl;
}
accuracy: 1
time_ms: 80
memory_kb: 15048
final_rank: 10

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

int main(){
    int n, m, c;
    cin >> n >> m >> c;
    vector<vector<array<int, 2>>> G(n);
    bool ok = false;
    for(int i = 0; i < m; i++){
        int u, v, f;
        cin >> u >> v >> f;
        u--; v--;
        G[u].push_back({v, f});
        if(v == n-1) ok = true;
    }
    
    if(!ok){
        cout << -1 << '\n';
        return 0;
    }
    
    int ans = -1;
    vector<int> dist(n, 1000000009);
    priority_queue<array<int, 2>, vector<array<int, 2>>, greater<array<int, 2>>> Q;
    dist[0] = 0;
    Q.push({0, 0});
    while(!Q.empty()){
        int d = Q.top()[0];
        int pos = Q.top()[1];
        Q.pop();
        
        if(dist[pos] < d) continue;
        
        for(int i = 0; i < (int)G[pos].size(); i++){
            int nex = G[pos][i][0];
            int c = G[pos][i][1];
            if(nex == n-1){
                if(ans == -1) ans = d + c;
                else ans = min(ans, d + c);
            } else {
                if(dist[nex] <= d + c) continue;
                dist[nex] = d + c;
                Q.push({d + c, nex});
            }
        }
        
        if(pos != 0){
            if(dist[pos-1] > d+c){
                dist[pos-1] = d+c;
                Q.push({d+c, pos-1});
            }
        }
        if(pos != n-1){
            if(dist[pos+1] > d+c){
                dist[pos+1] = d+c;
                Q.push({d+c, pos+1});
            }
        }
    }
    
    cout << ans << '\n';
}
accuracy: 1
time_ms: 70
memory_kb: 11556
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll llINF = 9000000000000000000ll;

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

int main(){
    ll n,m,c;
    cin>>n>>m>>c;
    vector<vector<pair<int,ll>>> g(2*n);
    for(int i=0;i<n;i++) g[n+i].push_back(make_pair(i,0));
    for(int i=1;i<n;i++)
    {
        g[i].push_back(make_pair(i-1,c));
        g[i-1].push_back(make_pair(i,c));
    }
    for(int i=0;i<m;i++)
    {
        ll a,b,f;
        cin>>a>>b>>f;
        a--,b--;
        g[a].push_back(make_pair(n+b,f));
    }
    
    vector<ll> dist(2*n,llINF);
    dist[0] = 0;
    auto comp = [&](int a , int b){return dist[a] > dist[b];};
    priority_queue<int,vector<int>,decltype(comp)> pq(comp);
    pq.push(0);
    while(!pq.empty())
    {
        int p = pq.top();
        pq.pop();
        for(auto [ps,l] : g[p])
        {
            if(chmin(dist[ps] , dist[p] + l)) pq.push(ps);
        }
    }
    
    /*
    for(int i=0;i<n;i++) cout<<dist[i]<<" ";
    cout<<endl;
    for(int i=n;i<2*n;i++) cout<<dist[i]<<" ";
    cout<<endl;
    */
    ll ans = dist.back();
    cout<<(ans == llINF ? -1 : ans)<<endl;
    //cout<<dist.back()<<endl;
}
accuracy: 1
time_ms: 120
memory_kb: 36272
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
const long long mod=998244353;
const long long hmod=46216567629137;
const long double PI=acos(-1);
int main(){
    cin.tie(0)->sync_with_stdio(0);
    cout.tie(0);
    int N,M;
    ll C;
    cin>>N>>M>>C;
    int a[M+1],b[M+1];
    ll f[M+1];
    vector<pair<ll,int>>G[N*2+1];
    for(int i=1;i<=M;i++){
        cin>>a[i]>>b[i]>>f[i];
    }
    for(int i=1;i<=N;i++){
        G[i].push_back({0,i+N});
    }
    for(int i=1;i<=N;i++){
        if(i!=1) G[i+N].push_back({C,i-1+N});
        if(i!=N) G[i+N].push_back({C,i+1+N});
    }
    for(int i=1;i<=M;i++){
        G[a[i]+N].push_back({f[i],b[i]});
    }
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>>PQ;
    ll dist[N*2+1];
    bool already[N*2+1];
    for(int i=1;i<=N*2;i++){
        dist[i]=2e18;
        already[i]=0;
    }
    dist[1]=0;
    PQ.push({0,1});
    while(!PQ.empty()){
        int pos=PQ.top().second;
        ll cost=PQ.top().first;
        PQ.pop();
        if(already[pos]) continue;
        already[pos]=1;
        rep(i,G[pos].size()){
            int nex=G[pos][i].second;
            ll next_cost=cost+G[pos][i].first;
            if(already[nex]) continue;
            if(next_cost<dist[nex]){
                dist[nex]=next_cost;
                PQ.push({next_cost,nex});
            }
        }
    }
    if(dist[N]==2e18) cout<<"-1\n";
    else cout<<dist[N]<<"\n";
}
accuracy: 1
time_ms: 100
memory_kb: 38828
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
int main() {
    int n, m, c; cin >> n >> m >> c;
    vector<vector<pint>> graph(n + 1);
    rep(i, m) {
        int a, b, f; cin >> a >> b >> f;
        a--, b--;
        if (b == n - 1)b++;
        graph[a].emplace_back(b, f);
    }
    rep(i, n - 1) {
        graph[i].emplace_back(i + 1, c);
        graph[i + 1].emplace_back(i, c);
    }
    min_priority_queue<pint> pq;
    vector<int> dist(n + 1, inf);
    pq.emplace(dist[0] = 0, 0);
    while (!pq.empty()) {
        auto [d, v] = pq.top(); pq.pop();
        if (dist[v] < d)continue;
        for (auto [nv, nd] : graph[v]) {
            nd += d;
            if (dist[nv] <= nd)continue;
            pq.emplace(dist[nv] = nd, nv);
        }
    }
    if (dist[n] == inf)cout << -1 << endl;
    else cout << dist[n] << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 17052
final_rank: 8

code_snippet: # include <algorithm>
# include <bitset>
# include <complex>
# include <cmath>
#define _USE_MATH_DEFINES
#include <assert.h>
# include <math.h>
# include <deque>
# include <exception>
# include <fstream>
# include <functional>
# include <iomanip>
# include <ios>
# include <iosfwd>
# include <iostream>
# include <istream>
# include <iterator>
# include <limits>
# include <list>
# include <locale>
# include <map>
# include <memory>
# include <new>
# include <numeric>
# include <ostream>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <stdexcept>
# include <streambuf>
# include <string>
# include <typeinfo>
# include <utility>
# include <valarray>
# include <vector>
# include <array>
# include <atomic>
# include <chrono>
# include <condition_variable>
# include <forward_list>
# include <future>
# include <initializer_list>
# include <mutex>
# include <random>
# include <ratio>
# include <regex>
# include <scoped_allocator>
# include <system_error>
# include <thread>
# include <tuple>
# include <typeindex>
# include <type_traits>
# include <unordered_map>
# include <unordered_set>
# include <bitset>
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for (ll i = 0;i < (ll)(n);i++)
#define Yes cout << "Yes" << "\n"// YESの短縮
#define No cout << "No" << "\n"// NOの短縮
#define rtr0 return(0)//return(0)の短縮
#define gyakugen(x) modpow(x,mod - 2,mod);
#define agyakugen(x) modpow(x,amod - 2,amod);
#define st(A) sort(A.begin(),A.end());
#define rst(A) sort(A.rbegin(),A.rend());
#define rev(A) reverse(A.begin(),A.end());
using namespace std;
//using namespace ranges;
using ll = long long;//63bit型整数型
using ld = long double;//doubleよりも長い値を保存できるもの
using ull = unsigned long long;//符号がない64bit型整数
//ld m_pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679;
ll mod = 998244353;
ll amod = 1000000007;
ll MINF = -5000000000000000000;
ll INF = 5000000000000000000;
ll inf = 2000000000;
ll minf = -2000000000;
ll BAD = -1;
ll zero = 0;
ld EPS = 1e-10;
vector<ll>randomhash = {(ll)1e9 + 7,(ll)1e9 + 801,((ll)1e8 * 8) + 29,((ll)1e8 * 7) + 159,((ll)1e8 * 9) + 221};
vector<ll>tate = {0,-1,0,1};//グリッド上の全探索時の四方向の上下のチェック
vector<ll>yoko = {1,0,-1,0};//グリッド上の全探索時の四方向の右左のチェック
vector<ll>etate = {0,-1,-1,-1,0,1,1,1};//グリッド上の全探索時の八方向の上下のチェック
vector<ll>eyoko = {1,1,0,-1,-1,-1,0,1};//グリッド上の全探索時の八方向の右左のチェック
vector<ll>hexsax = {0,1,1,0,-1,-1};
vector<ll>hexsay = {1,1,0,-1,-1,0};
//返り値は素数のリスト。
vector < bool > isprime;
vector < ll > Era(int n){//書き方 vector<ll>[] = Era(x); とやるとxまでの素数が出てくる。
	isprime.resize(n, true);
	vector < ll > res;
	isprime[0] = false;
	isprime[1] = false;
	for(ll i = 2; i < n; ++i) isprime[i] = true;
	for(ll i = 2; i < n; ++i) {
		if(isprime[i]) {
			res.push_back(i);
			for(ll j = i * 2; j < n; j += i) isprime[j] = false;
		}
	}
	return res;
}
ll ceil_div(ll a, ll b){
    if (b <= 0) return INF; // invalid (分母<=0 のときは不可能と扱う)
    return (a + b - 1) / b;
}
//　　　　　　素数判定 21~35
ull modmul(ull a,ull b,ull mod) {
    return (ull)a*b%mod;
}
ll modpow(ll a, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

long long npow(long long a, long long n){
    long long res = 1;
    while (n > 0) {
		if (n & 1) res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}
//     モッドを使った累乗
long long isqrt(long long num){
    return((long long)sqrtl(num));
}
ld get_theta(ld px,ld py,ld fx,ld fy,ld sx,ld sy){
    ld fxv = fx-px;
    ld fyv = fy-py;
    ld sxv = sx-px;
    ld syv = sy-py;
    ld fsv = fxv*sxv + fyv*syv;
    ld pfs = (ld)sqrt(fxv*fxv+fyv*fyv);
    ld pss = (ld)sqrt(sxv*sxv+syv*syv);
    return acos(fsv/(pfs*pss))*180/M_PI;
};
ld Euclidean_distance(ll x1,ll y1,ll x2,ll y2){
    ld x = abs((ld)x1 - (ld)x2);
    ld y = abs((ld)y1 - (ld)y2);
    return sqrt((x*x) + (y*y));
};
ll Manhattan_distance(ll x1,ll y1,ll x2,ll y2){
    return abs(x1-x2)+abs(y1-y2);
};
void change_bit(ll N,ll start,vector<ll>&X){
    for(ll i = start;i>=0;i--){
        ll a = npow(2,i);
        if(N/a==1){
            X[i]=1;
            N-=a;
        }
    }
}
ll popcount(ll x) {
    int count = 0;
    while (x) {
        count += x & 1;
        x >>= 1;
    }
    return count;
}

ll cutup(ll a,ll b){
    return (a+b-1)/b;
}
void Run_Length_Encoding(vector<ll>A,vector<pair<ll,ll>>&RLE){
    RLE.push_back({A[0],1});
    ll N = A.size();
    for(int i = 1;i<N;i++){
        if(RLE[RLE.size()-1].first==A[i])RLE[RLE.size()-1].second++;
        else RLE.push_back({A[i],1});
    }
}
bool is_in_grid(ll i,ll ii,ll H,ll W){
    bool res = false;
    if(i>=0&&i<H&&ii>=0&&ii<W)res=true;
    return res;
}
template<class T>
struct rolling_hash{
    vector<ull>Power,hash,InvPower;
    ll B = 0;
    ll MOD = 0;
    void set_number(ll base,ll mod){
        B = base;
        MOD = mod;
    }
    void do_hash(const T &S) {
        ll N = S.size();
        Power.resize(N+1);
        InvPower.resize(N+1);
        hash.resize(N+1);
        Power[0] = 1;
        InvPower[0] = 1;
        for (ll i = 0;i<N;i++) {
            Power[i + 1] = modmul(Power[i],B,MOD);
            InvPower[i + 1] = modpow(Power[i+1],MOD-2,MOD);
            hash[i + 1] = (hash[i] + modmul(S[i], Power[i],MOD))%MOD;
        }
    }
    ll get_hash(ll l, ll r) {
        ull res = (hash[r]+MOD-hash[l])%MOD;
        res = modmul(res,InvPower[l],MOD);
        return res;
    }
};
template<class T>
struct combination{
  public:
    vector<T>factorial;
    ll MOD;
    ll N;
    void reset(T n,T mod){
        N = n+1;
        factorial.assign(N,1);
        MOD = mod;
    }
    void calu(){
        for(ll i = 1;i<N;i++){
            factorial[i] = (factorial[i-1]*(i))%MOD;
        }
    }
    T get(T n, T r){
        ll a = factorial[n];
        ll b = (factorial[r]*(factorial[n-r]))%MOD;
        b = modpow(b,MOD - 2,MOD);
        return (a*b)%MOD;
    }
};
template<class T>
struct dijkstra{
  public:
	vector<vector<pair<T,T>>>graph;
	vector<T>ans;
	priority_queue<pair<T,T>,vector<pair<T,T>>,greater<pair<T,T>>>pq;
    void do_dijkstra(T start){//頂点xからダイクストラを行う
		pq.push({0,start});
		ans[start] = 0;
		while(true){
			if(pq.empty())break;
			T cost = pq.top().first;
			T vertex = pq.top().second;
			pq.pop();
            if (cost > ans[vertex]) continue; 
			for(T i = 0;i<graph[vertex].size();i++){
				T nextvertex = graph[vertex][i].first;
				T nextcost = graph[vertex][i].second + cost;
				if(ans[nextvertex] <= nextcost)continue;
					ans[nextvertex] = nextcost;
					pq.push({nextcost,nextvertex});
			}
		}
	}
	void make_indirectedgraph(T u,T v,T cost){//無向辺のグラフ作成
		graph[u].push_back({v,cost});
		graph[v].push_back({u,cost});
	}
	void make_directedgraph(T u,T v,T cost){//有向辺のグラフ作成
		graph[u].push_back({v,cost});
	}
	T output(T end){//答えを出す
		return ans[end];
	} 
	void reset(T N){//リセット
		graph.assign(N, {});
        ans.assign(N, INF);
	}
};
template<class T>
struct unionfind {
public:
    vector<T> parent, rank;
    void reset(T N) { // 初期化
        parent.resize(N);
        rank.assign(N, 1); // 各集合のサイズを 1 にする
        for (T i = 0; i < N; i++) parent[i] = i;
    }
    T leader(T x) { // 経路圧縮による親の取得
        if (parent[x] == x) return x;
        return parent[x] = leader(parent[x]); // 経路圧縮
    }
    void marge(T x, T y) { // ランクによるマージ
        T a = leader(x), b = leader(y);
        if(a!=b){
            if (rank[a] < rank[b]) swap(a, b);
            parent[b] = a;
            rank[a] += rank[b]; // サイズを更新    
        }
    }
    bool same(T x, T y) { // 同じ集合か判定
        return leader(x) == leader(y);
    }
    T size(T x) { // 集合のサイズを取得
        return rank[leader(x)];
    }
    void check(T N) { // デバッグ用: 親の確認
        for (T i = 0; i < N; i++) cout << parent[i] << " ";
        cout << "\n";
    }
};
//セグ木
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
    public:
        segtree() : segtree(0) {}
        segtree(int n) : segtree(std::vector<S>(n, e())) {}
        segtree(const std::vector<S>& v) : _n(int(v.size())){
            log = ceil_pow2(_n);
            size = 1 << log;
            d = std::vector<S>(2 * size, e());
            for (int i = 0; i < _n; i++) d[size + i] = v[i];
            for (int i = size - 1; i >= 1; i--) {
                update(i);
            }
        }
  
        void set(int p, S x) {
            assert(0 <= p && p < _n);
            p += size;
            d[p] = x;
            for (int i = 1; i <= log; i++) update(p >> i);
        }
  
        S get(int p) {
            assert(0 <= p && p < _n);
            return d[p + size];
        }
  
        S prod(int l, int r) {
            assert(0 <= l && l <= r && r <= _n);
            S sml = e(), smr = e();
            l += size;
            r += size;
  
            while (l < r) {
                if (l & 1) sml = op(sml, d[l++]);
                if (r & 1) smr = op(d[--r], smr);
                l >>= 1;
                r >>= 1;
            }
            return op(sml, smr);
        }
  
        S all_prod() { return d[1]; }
  
        template <bool (*f)(S)> int max_right(int l) {
            return max_right(l, [](S x) { return f(x); });
        }
        template <class F> int max_right(int l, F f) {
            assert(0 <= l && l <= _n);
            assert(f(e()));
            if (l == _n) return _n;
            l += size;
            S sm = e();
            do{
                while (l % 2 == 0) l >>= 1;
                if (!f(op(sm, d[l]))) {
                    while (l < size) {
                        l = (2 * l);
                        if (f(op(sm, d[l]))) {
                            sm = op(sm, d[l]);
                            l++;
                        }
                    }
                    return l - size;
                }
                sm = op(sm, d[l]);
                l++;
            }while ((l & -l) != l);
            return _n;
        }
  
        template <bool (*f)(S)> int min_left(int r) {
            return min_left(r, [](S x) { return f(x); });
        }
        template <class F> int min_left(int r, F f) {
            assert(0 <= r && r <= _n);
            assert(f(e()));
            if (r == 0) return 0;
            r += size;
            S sm = e();
            do{
                r--;
                while (r > 1 && (r % 2)) r >>= 1;
                if (!f(op(d[r], sm))) {
                    while (r < size) {
                        r = (2 * r + 1);
                        if (f(op(d[r], sm))) {
                            sm = op(d[r], sm);
                            r--;
                        }
                    }
                    return r + 1 - size;
                }
                sm = op(d[r], sm);
            }while ((r & -r) != r);
            return 0;
        }
  
    private:
        int _n, size, log;
        std::vector<S> d;
  
        void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
        int ceil_pow2(int n) {
            int x = 0;
            while ((1U << x) < (unsigned int)(n)) x++;
            return x;
        }
};

//遅延セグ木
template <class S,S (*op)(S, S),S (*e)(),class F,S (*mapping)(F, S),F (*composition)(F, F),F (*id)()>
struct lazy_segtree {

    public:
        lazy_segtree() : lazy_segtree(0) {}
        lazy_segtree(int n) : lazy_segtree(std::vector<S>(n, e())) {}
        lazy_segtree(const std::vector<S>& v) : _n(int(v.size())) {
            log = ceil_pow2(_n);
            size = 1 << log;
            d = std::vector<S>(2 * size, e());
            lz = std::vector<F>(size, id());
            for (int i = 0; i < _n; i++) d[size + i] = v[i];
            for (int i = size - 1; i >= 1; i--) {
                update(i);
            }
        }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        return d[p];
    }

    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return e();

        l += size;
        r += size;

        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push(r >> i);
        }

        S sml = e(), smr = e();
        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }

        return op(sml, smr);
    }

    S all_prod() { return d[1]; }

    void apply(int p, F f) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = mapping(f, d[p]);
        for (int i = 1; i <= log; i++) update(p >> i);
    }
    void apply(int l, int r, F f) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return;

        l += size;
        r += size;

        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }

        {
            int l2 = l, r2 = r;
            while (l < r) {
                if (l & 1) all_apply(l++, f);
                if (r & 1) all_apply(--r, f);
                l >>= 1;
                r >>= 1;
            }
            l = l2;
            r = r2;
        }

        for (int i = 1; i <= log; i++) {
            if (((l >> i) << i) != l) update(l >> i);
            if (((r >> i) << i) != r) update((r - 1) >> i);
        }
    }

    template <bool (*g)(S)> int max_right(int l) {
        return max_right(l, [](S x) { return g(x); });
    }
    template <class G> int max_right(int l, G g) {
        assert(0 <= l && l <= _n);
        assert(g(e()));
        if (l == _n) return _n;
        l += size;
        for (int i = log; i >= 1; i--) push(l >> i);
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!g(op(sm, d[l]))) {
                while (l < size) {
                    push(l);
                    l = (2 * l);
                    if (g(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*g)(S)> int min_left(int r) {
        return min_left(r, [](S x) { return g(x); });
    }
    template <class G> int min_left(int r, G g) {
        assert(0 <= r && r <= _n);
        assert(g(e()));
        if (r == 0) return 0;
        r += size;
        for (int i = log; i >= 1; i--) push((r - 1) >> i);
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!g(op(d[r], sm))) {
                while (r < size) {
                    push(r);
                    r = (2 * r + 1);
                    if (g(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

    private:
        int _n, size, log;
        std::vector<S> d;
        std::vector<F> lz;
        int ceil_pow2(int n) {
            int x = 0;
            while ((1U << x) < (unsigned int)(n)) x++;
            return x;
        }
        void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
        void all_apply(int k, F f) {
            d[k] = mapping(f, d[k]);
            if (k < size) lz[k] = composition(f, lz[k]);
        }
        void push(int k) {
            all_apply(2 * k, lz[k]);
            all_apply(2 * k + 1, lz[k]);
            lz[k] = id();
        }
};
struct Euler_Tour{//最小共通祖先,部分木のコスト,通り道のコスト,のグラフを作る部分(オイラーツアー)
    //必要なもの集
    //セグ木は2*Nがベース
    //LCA(最小共通祖先)discovery,finish,visit,high
    //とある頂点xを根とする部分木の範囲 discovery,finish
    //頂点xを根とする部分木の辺と頂点のコストの総和 discovery,finish,vcost1,ecost1
    //頂点xを根とする頂点yまでの最短の辺と頂点のコストの総和 discovery,finish,vcost2,ecost2
    vector<int>discovery,finish,visit,high,vweight,vcost1,vcost2,ecost1,ecost2;
    vector<int>other;
    vector<vector<pair<int,int>>>graph;
    int cnt;
    int othercnt;
    void reset(ll N){
        cnt = 0;
        othercnt = 0;
        other.assign(2*N,0);
        discovery.assign(N,inf);
        finish.assign(N,minf);
        vweight.assign(N,0);
        graph.assign(N,vector<pair<int,int>>(0));
        visit.assign(2*N,0);
        high.assign(2*N,0);
        vcost1.assign(2*N,0);
        vcost2.assign(2*N,0);
        ecost1.assign(2*N,0);
        ecost2.assign(2*N,0);
    };
    void make_graph(ll u,ll v,ll cost){
        if(max(u,v)>graph.size()){
            cout << "not reset or out of range" << "\n";
            return;
        }
        graph[u].push_back({v,cost});
        graph[v].push_back({u,cost});
    }
    void set_vweight(ll vertex,ll cost){
        vweight[vertex]+=cost;
    }
    void DFS(ll vertex,ll nowdepth,ll cost){
        if(discovery[vertex]==inf){
            vcost1[cnt]=vweight[vertex];
            vcost2[cnt]=vweight[vertex];
        }
        else{
            vcost1[cnt]=0;
            vcost2[cnt]=0;
        }
        ecost1[cnt]=cost;
        ecost2[cnt]=cost;
        discovery[vertex]=min(discovery[vertex],cnt);
        visit[cnt]=vertex;
        high[cnt]=nowdepth;
        for(int i = 0;i<graph[vertex].size();i++){
            int x = graph[vertex][i].first;
            int nextcost = graph[vertex][i].second;
            if(discovery[x]!=inf&&graph[vertex].size()==1)othercnt++;
            other[cnt]=othercnt;
            if(discovery[x]==inf){
                cnt++;
                DFS(x,nowdepth+1,nextcost);
                cnt++;
                visit[cnt]=vertex;
                high[cnt]=nowdepth;
                vcost1[cnt]=0;
                ecost1[cnt]=0;
                vcost2[cnt]=vweight[x]*-1;
                ecost2[cnt]=nextcost*-1;
            }
            other[cnt]=othercnt;
        }
        finish[vertex]=cnt+1;
        return;
    }
    int get_size(){
        ll res = high.size()-1;
        return res;
    }
    int get_vcost1(ll i){
        return ecost1[i];
    }
    int get_vcost2(ll i){
        return vcost2[i];
    }
    int get_ecost1(ll i){
        return vcost1[i];
    }
    int get_ecost2(ll i){
        return ecost2[i];
    }
    int get_high(ll i){
        return high[i];
    }
    int get_visit(ll i){
        return visit[i];
    }
    int get_discovery(ll i){
        return discovery[i];
    }
    int get_finish(ll i){
        return finish[i];
    }
};
//遅延セグ木のベース
//型
using segS = ll;
segS oop(segS a,segS b){
    return (a+b)%mod;
}
segS ee(){
    return 0;
}
/*struct segS{
    ll mi = 0;
    ll ma = 0;
};
segS oop(segS a,segS b){
    segS res;
    res.mi = min(a.mi,b.mi);
    res.ma = max(a.ma,b.ma);
    return res;
}
segS ee(){
    segS res;
    res.mi = INF;
    res.ma = MINF;
    return res;
}*/

//using lazyS = ll;
using lazyS = ll;
using lazyF = ll;
lazyS e(){
    lazyS res;
    res = 1;
    return res;
}//範囲外などを起こしてしまったときの返り値
lazyS op(lazyS a, lazyS b){
    lazyS res;
    res = a+b;
    return res; 
}//操作したいこと
lazyS mapping(lazyF f, lazyS x){ 
    x= (x*f)%mod;
    return x; 
}//下まで伝播させたいこと
lazyF composition(lazyF f, lazyF g){ return g = (g*f)%mod; }//まとめてやった場合おこしたいこと
lazyF id(){ return 1; }//遅延セグ木のベース
/*
using lazyS = ll;
using lazyF = ll;
lazyS e(){ return 0;}//範囲外などを起こしてしまったときの返り値
lazyS op(lazyS a, lazyS b){ return a+b; }//操作したいこと
lazyS mapping(lazyF f, lazyS x){ return x /= f; }//下まで伝播させたいこと
lazyF composition(lazyF f, lazyF g){ return g /= f; }//まとめてやった場合おこしたいこと
lazyF id(){ return 1; }//遅延セグ木のベース
*/

int main(){
ll N,M,C;
cin >> N >> M >> C;
dijkstra<ll>dik;
dik.reset(N+1);
for(int i = 0;i<M;i++){
    ll a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    if(b==N-1)b++;
    dik.make_directedgraph(a,b,c);
}
for(int i = 0;i<N-1;i++){
    dik.make_indirectedgraph(i,i+1,C);
}
//Yes;
dik.do_dijkstra(0);
cout << (dik.output(N) == INF ? -1 : dik.output(N)) << "\n";
}
accuracy: 1
time_ms: 90
memory_kb: 22920
final_rank: 11

code_snippet: #include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<utility>
#include<string>
#include<vector>
#include<bit>
#include<bitset>
#include<tuple>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;

void fix(int x){
  cout << fixed << setprecision(x);
}

int main(){
  long int N, M, C, A, B, D;
  cin >> N >> M >> C;
  vector<vector<pair<long int, long int> > > V(N + 1);
  vector<long int> ans(N + 1, 1e18);
  vector<long int> ans2(N + 1, 0);
  for (long int i = 0; i < M; i++){
    cin >> A >> B >> D;
    A--;
    B--;
    V.at(B).push_back(make_pair(A, D));
    if (B == N - 1){
      V.at(N).push_back(make_pair(A, D));
    }
  }
  if (V.at(N - 1).size() == 0){
    cout << -1 << endl;
    return 0;
  }
  ans.at(N) = 0;
  ans2.at(N) = 2;
  ans2.at(N - 1) = 1;
  A = N;
  priority_queue<pair<long int, long int> > PQ;
  for (long int i = 0; i < N; i++){
    for (long int j = 0; j < V.at(A).size(); j++){
      if (ans.at(V.at(A).at(j).first) > ans.at(A) + V.at(A).at(j).second){
        PQ.push(make_pair(1000000000000000000 - ans.at(A) - V.at(A).at(j).second, V.at(A).at(j).first));
        ans.at(V.at(A).at(j).first) = ans.at(A) + V.at(A).at(j).second;
      }
    }
    while (i < N - 1){
      B = PQ.top().second;
      D = PQ.top().first;
      if (ans2.at(B) == 0){
        ans2.at(B) = 1;
        A = B;
        break;
      }else if(ans2.at(B) == 1){
        ans2.at(B) = 2;
        PQ.pop();
        if (A != 0 && ans2.at(B - 1) == 0){
          if (ans.at(B - 1) > 1000000000000000000 - D + C){
            PQ.push(make_pair(D - C, B - 1));
            ans.at(B - 1) = 1000000000000000000 - D + C;
          }
        }
        if (A != N - 1 && ans2.at(B + 1) == 0){
          if (ans.at(B + 1) > 1000000000000000000 - D + C){
            PQ.push(make_pair(D - C, B + 1));
            ans.at(B + 1) = 1000000000000000000 - D + C;
          }
        }
      }else{
        PQ.pop();
      }
    }
  }
  cout << ans.at(0) << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 15208
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
// #include<atcoder/all>
// using mint = atcoder::modint998244353;
using ld = long double;
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename T>bool chmin(T&a,T b){return b<a?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return b>a?(a=b,1):0;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N,M,C;
    cin>>N>>M>>C;
    vector<vector<pair<int,int>>> G(N);
    rep(i,M){
        int a,b,f;
        cin>>a>>b>>f;
        a--;b--;
        G[b].push_back({a,f});
    }
    using P=pair<int,int>;
    priority_queue<P,vector<P>,greater<P>> pq;
    vector<int> dp(N,1e9);
    for(auto [e,c]: G[N-1]){
        if(chmin(dp[e],c)){
            pq.push({c,e});
        }
    }
    rep(i,N-1){
        G[i].push_back({i+1, C});
        G[i+1].push_back({i, C});
    }
    while(!pq.empty()){
        auto [k,v]=pq.top();
        pq.pop();
        if(dp[v]>k) continue;
        for(auto [e,c]:G[v]){
            if(chmin(dp[e],dp[v]+c)){
                pq.push({dp[e],e});
            }
        }
    }
    if(dp[0]==1e9) dp[0]=-1;
    cout<<dp[0]<<"\n";
}
accuracy: 1
time_ms: 40
memory_kb: 17076
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a; i<(n); i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto i:a)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
using Int = long long;
const Int INF = 1LL << 60;
const int inf = 1001001001;
vector<int> dxs = {1, 0, -1, 0};
vector<int> dys = {0, 1, 0, -1};
struct Edge{
Int to, w;
Edge(Int to, Int w) : to(to), w(w) {}
};
int main(){
    Int n,m,c;
    cin>>n>>m>>c;
    vector<vector<Edge>> G(n);
    rep(i,0,m){
        Int a,b,t;
        cin>>a>>b>>t;
        a--;b--;
        G[a].push_back({b,t});
    }
    vector<Int> dist(n,INF);
    dist[0]=0;
    queue<Int> que;
    que.push(0);
    Int ans=INF;
    while(que.size()){
        Int pos=que.front();
        que.pop();
        fore(to,G[pos]){
            if(to.to==n-1)ans=min(ans,dist[pos]+to.w);
            if(dist[to.to]>dist[pos]+to.w){
                dist[to.to]=dist[pos]+to.w;
                que.push(to.to);
            }
        }
        if(pos-1>=0){
            if(dist[pos-1]>dist[pos]+c){
                dist[pos-1]=dist[pos]+c;
                que.push(pos-1);
            }
        }
        if(pos+1<n){
            if(dist[pos+1]>dist[pos]+c){
                dist[pos+1]=dist[pos]+c;
                que.push(pos+1);
            }
        }
    }
    if(ans==INF)cout<<-1<<endl;
    else cout<<ans<<endl;
}
accuracy: 1
time_ms: 50
memory_kb: 12392
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)
#define all(a) (a).begin(),(a).end()

const ll INF = 1ll << 61;

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

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int N, M, C;
    cin >> N >> M >> C;
    
    vector<vector<pair<int, ll>>> G(N + 1);
    rep(i, 0, M) {
        int a, b, f;
        cin >> a >> b >> f;
        a--, b--;
        if (b == N - 1) b = N;
        G[a].push_back({b, f});
    }
    
    rep(i, 0, N) {
        if (i != 0) {
            G[i].push_back({i - 1, C});
            G[i - 1].push_back({i, C});
        }
        if (i != N - 1) {
            G[i].push_back({i + 1, C});
            G[i + 1].push_back({i, C});
        }
    }
    
    vector<ll> dist(N + 1, INF);
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que;
    dist[0] = 0;
    que.push({0, 0});
    
    while (!que.empty()) {
        ll d = que.top().first;
        int v = que.top().second;
        que.pop();
        
        if (dist[v] < d) continue;
        
        for (auto e : G[v]) {
            if (chmin(dist[e.first], dist[v] + e.second)) {
                que.push({dist[e.first], e.first});
            }
        }
    }
    
    cout << (dist[N] == INF ? -1 : dist[N]) << '\n';
}
accuracy: 1
time_ms: 50
memory_kb: 31992
final_rank: 12

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

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

  ll N, M, C;
  cin >> N >> M >> C;

  vector<vector<pair<ll, ll>>> g(2 * N);
  for(ll i = 0, u, v, w; i < M; i++) {
    cin >> u >> v >> w;
    u--, v--;
    g[u].emplace_back(v + N, w);
  }

  for(ll i = 0; i < N; i++) {
    g[i + N].emplace_back(i, 0);
    if(i != N - 1) {
      g[i].emplace_back(i + 1, C);
      g[i + 1].emplace_back(i, C);
    }
  }

  vector<ll> d(2 * N, 1e18);
  d[0] = 0;
  auto chmin = [&](auto &a, const auto &b) { return a > b ? (a = b, true) : false; };
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> q;
  q.emplace(0, 0);
  while(!q.empty()) {
    auto [tmp, v] = q.top();
    q.pop();
    if(tmp > d[v]) { continue; }
    for(auto &[nv, c] : g[v]) {
      if(chmin(d[nv], d[v] + c)) { q.emplace(d[nv], nv); }
    }
  }

  cout << (d[2 * N - 1] == 1e18 ? -1 : d[2 * N - 1]) << "\n";
}
accuracy: 1
time_ms: 70
memory_kb: 35352
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#define asb(a,b) ((a)-(b)>0?(a)-(b):(b)-(a))
#define atio(v,n) for(int g=0;g<(n);++g)cin >> v[g]
#define atdp(v,en) {int bbbbbb=0;for(auto o:v){if(bbbbbb)cout << en;bbbbbb=1;cout << o;}cout << endl;}
#define atfs(a) printf("%lld %lld\n",(a).first,(a).second)
#define ri(n) rp(i,n)
#define rj(n) rp(j,n)
#define rk(n) rp(k,n)
#define rl(n) rp(l,n)
#define rp(e,c) for(int e=0;e<(c);++e)
#define rix(s,h) rpx(i,s,h)
#define rjx(s,h) rpx(j,s,h)
#define rkx(s,h) rpx(k,s,h)
#define rlx(s,h) rpx(l,s,h)
#define rpx(e,s,h) for(int e=s;e<(h);++e)
#define ci(d,r) ((d)/(r)+(((d)%(r))!=0))
#define pn {pr("No");return 0;}
#define py {pr("Yes");return 0;}
#define pr(a) cout << (a) << endl
#define bgen(a) a.begin(),a.end()
#define INF 114514810
#define LNF 1ll<<60
#define asr(q,n) (0<=(q) && (q)<(n))
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using si=set<int>;
using sll=set<ll>;
using qi=queue<int>;
using qll=queue<ll>;
using qpii=queue<pii>;
using qpll=queue<pll>;
using vst=vector<string>;
using vsi=vector<si>;
using vvi=vector<vi>;
using vvl=vector<vll>;
using tiii=tuple<int,int,int>;
using tlll=tuple<ll,ll,ll>;
using mii=map<int,int>;
using mll=map<ll,ll>;
using stki=stack<int>;
using stkll=stack<ll>;
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};

int is_prime(ll n){
  for(ll i=2;i*i<=n;++i)if(n%i==0)return 0;
  return 1;
}

template <typename T>
int factor(ll n,map<T,T>& m){
  for(ll i=2;i*i<=n;++i){
    while(n%i==0){
      n/=i;
      ++m[i];
    }
  }
  if(n!=1)++m[n];
  return 0;
}

template <typename T>
int divider(ll n,set<T>& s){
  for(ll i=2;i*i<=n;++i){
    if(n%i==0){
      s.insert(i);
      s.insert(n/i);
    }
  }
  return 0;
}

template <typename T>
int primes(ll n,set<T>& s){
  vi isp(n,1);
  isp[0]=0;
  int t=0;
  int c=1;
  while(1){
    do{
      if(t>=n)break;
      ++t;
    }while(!isp[t]);
    if(t>=n)break;
    s.insert(t+1);
    c=2*t+1;
    while(c<n){
      isp[c]=0;
      c+=t+1;
    }
  }
  return 0;
}

template <typename T>
int pcp(vector<T>& x,map<T,T>& mi){
	set<T> s;
	ri(x.size())s.insert(x[i]);
	T p=0;
  map<T,T> m;
	while(s.size()){
		m[*s.begin()]=p;
    mi[p]=*s.begin();
		s.erase(*s.begin());
		++p;
	}
	ri(x.size())x[i]=m[x[i]];
	return 0;
}

ll gcd(ll a,ll b){
  while(a%=b)swap(a,b);
  return b;
}

pll eeu(ll a,ll b,ll c){
	if(a==c && b==0)return pll(1,0);
	pll x=eeu(b,a%b,c);
	return pll(x.second,x.first-(a/b)*x.second);
}

pll lie(ll a,ll b,ll c){
	ll gab=gcd(a,b);
	ll cd=c/gab;
	pll x=eeu(a,b,gab);
	return pll(cd*x.first,cd*x.second);
}

struct mint{// can be used only the case mod is prime number
    ll x,mod;
    pll _eeu(ll a,ll b,ll c){
	    if(a==c && b==0)return pll(1,0);
	    pll x=_eeu(b,a%b,c);
	    return pll(x.second,x.first-(a/b)*x.second);
    }
    ll inv(ll a){
      pll x=_eeu(a,mod,1);
      return (x.first%mod+mod)%mod;
    }
    mint(ll x=0,ll mod=998244353) : mod(mod),x(x) {x=(x%mod+mod)%mod;}
    mint operator-() const {return mint(mod,-x);}
    mint& operator=(const mint& a){x=a.x%mod;return *this;}
    mint& operator+=(const mint& a){x=(x+a.x)%mod;return *this;}
    mint& operator-=(const mint& a){x=((x-a.x)%mod+mod)%mod;return *this;}
    mint& operator*=(const  mint& a){x=(x*a.x)%mod;return *this;}
    mint& operator=(const ll a){x=((a%mod)+mod)%mod;return *this;}
    mint& operator+=(const ll a){x=(x+a)%mod;return *this;}
    mint& operator-=(const ll a){x=((x-a)%mod+mod)%mod;return *this;}
    mint& operator*=(const ll a){x=((x*a)%mod+mod)%mod;return *this;}
    mint operator+(const mint& a)const{mint res(*this);return res+=a;}
    mint operator-(const mint& a)const{mint res(*this);return res-=a;}
    mint operator*(const mint& a)const{mint res(*this);return res*=a;}
    mint operator+(const ll a)const{mint res(*this);return res+=a;}
    mint operator-(const ll a)const{mint res(*this);return res-=a;}
    mint operator*(const ll a)const{mint res(*this);return res*=a;}
    // for prime mod
    mint& operator/=(const mint& a){return (*this)*=inv(a.x);} // Assumed that the law is the same for dividen and divider.
    mint& operator/=(const ll a){return (*this)*=inv(a);}
    mint operator/(const mint& a)const{mint res(*this);return res/=a;}
    mint operator/(const ll a)const{mint res(*this);return res/=a;}
    friend ostream& operator<<(ostream& os, const mint& m){os << m.x;return os;}
};

struct uf{
  int n;
  vi unfi,rank,sizu;
  uf(int n) : n(n){unfi=vi(n,-1);rank=vi(n);sizu=vi(n,1);}
  int root(int p){
    if(unfi[p]==-1)return p;
    else return unfi[p]=root(unfi[p]);
  }
  int unite(int b,int a){
    int ra=root(a);
    int rb=root(b);
    if(ra==rb)return 1;
    if(rank[ra]>rank[rb])swap(ra,rb);
    unfi[ra]=rb;
    if(rank[ra]==rank[rb])++rank[rb];
    sizu[rb]+=sizu[ra];
    return 0;
  }
};

template <typename T,class Fn>
struct sgt{ // 1-indexed
  vector<T> seg;
  int n;
  T d;
  Fn f;
  sgt(vector<T>& n2,T d,Fn f) : n(n2.size()),d(d), f(f){
    int b=n;
    while(!(b&1))b>>=1;
    if(b!=1){
      int c=0;
      b=n;
      while(b){b>>=1;++c;}
      n=1<<c;
    }
    seg=vector<T>(n<<1,d);
    b=n2.size();
    ri(b)seg[n+i]=n2[i];
    b=n;
    while(b>1){
      for(int i=b/2;i<b;++i)seg[i]=f(seg[2*i],seg[2*i+1]);
      b/=2;
    }
	return;
  }
  void update(int pos,T val){
    int i=n+pos;
    seg[i]=val;
    while(i/=2)seg[i]=f(seg[2*i],seg[2*i+1]);
	return;
  }
  T get(int l,int r){
    T tmp=d;
    int p=l;
    int c=0;
    while((p+(1<<c))<=r){
      if(p&(1<<c)){
        tmp=f(tmp,seg[(p>>c)+(n>>c)]);
        p+=1<<c;
      }
      ++c;
    }
    --c;
    while(p<r){
      if((r-p)&(1<<c)){
        tmp=f(tmp,seg[(p>>c)+(n>>c)]);
        p+=(1<<c);
      }
      --c;
    }
    return tmp;
  }
  T get(int pos){
    return seg[n+pos];
  }
};

void scc(vsi& s,vsi& g,vsi& gi){
  int n=g.size();
  vi id(n,INF),idi(n,-1);
  si rmn,ids;
  int cid=0;
  ri(n){
    rmn.insert(i);
    ids.insert(i);
  }
  while(rmn.size()){
    stack<pii> stk;
    stk.push(pii(*rmn.begin(),-1));
    while(stk.size()){
      pii tmp=stk.top();
      int cur=tmp.first;
      rmn.erase(cur);
      si::iterator itr;
      while((itr=g[cur].upper_bound(stk.top().second))!=g[cur].end()){
        stk.top().second=*itr;
        if(rmn.count(stk.top().second))break;
      }
      if(itr!=g[cur].end()){
        stk.push(pii(stk.top().second,-1));
      }else{
        id[cur]=cid;
        idi[cid]=cur;
        ++cid;
        stk.pop();
      }
    }
  }
  while(ids.size()){
    si subm,alr;
    stack<pii> stk;
    stk.push(pii(idi[*ids.rbegin()],-1));
    int idcrop=*ids.rbegin();
    while(stk.size()){
      pii tmp=stk.top();
      int cur=tmp.first;
      si::iterator itr;
      alr.insert(cur);
      while((itr=gi[cur].upper_bound(stk.top().second))!=gi[cur].end()){
        stk.top().second=*itr;
        if(idcrop>id[stk.top().second]&&(!alr.count(stk.top().second)))break;
      }
      if(itr!=gi[cur].end()){
        stk.push(pii(stk.top().second,-1));
      }else{
        subm.insert(cur);
        ids.erase(id[cur]);
        stk.pop();
      }
    }
    s.emplace_back(subm);
  }
}

const double eps=1e-10;
struct Point{
  double x,y;
  Point(double _x=0,double _y=0):x(_x),y(_y) {}
  Point operator-() {return Point(-x,-y);}
  Point& operator=(Point a){x=a.x;y=a.y;return *this;}
  Point& operator+=(Point a){x+=a.x;y+=a.y;return *this;}
  Point& operator-=(Point a){x-=a.x;y-=a.y;return *this;}
  Point& operator*=(double a){x*=a;y*=a;return *this;}
  Point& operator/=(double a){x/=a;y/=a;return *this;}
  Point operator+(Point a){return Point(*this)+=a;}
  Point operator-(Point a){return Point(*this)-=a;}
  Point operator*(double a){return Point(*this)*=a;}
  Point operator/(double a){return Point(*this)/=a;}
  bool operator<(Point a){return abs(x-a.x)<eps?x<a.x:y<a.y;}
  bool operator>(Point a){Point r(*this);return a<r;}
  bool operator<=(Point a){return !(Point(*this)>a);}
  bool operator>=(Point a){return !(Point(*this)<a);}
  bool operator==(Point a){return abs(x-a.x)<eps&&abs(y-a.y)<eps;}
  bool operator!=(Point a){return !(Point(*this)==a);}
  Point& rotate(double th){
    double xn=x*cos(th)-y*sin(th),yn=x*sin(th)+y*cos(th);
    x=xn,y=yn;
    return *this;
  }
  friend ostream& operator<<(ostream& os, const Point& p){os << fixed << setprecision(10) << p.x << ' ' << p.y;return os;}
};

double dot(Point p,Point q){return p.x*q.x+p.y*q.y;}
double cross(Point p,Point q){return p.x*q.y-p.y*q.x;}
double norm(Point p){return p.x*p.x+p.y*p.y;}
double abs(Point p){return sqrt(norm(p));}
double arg(Point p){return atan2(p.y,p.x);}

struct ve2{
  Point p1,p2,d;
  ve2(double _x=0,double _y=0,double _dx=0,double _dy=0,int _mode=0){
    p1.x=_x;
    p1.y=_y;
    d.x=_dx;
    d.y=_dy;
    if(_mode){
      p2=d;
      d=p2-p1;
    }else{
      p2=p1+d;
    }
  }
  ve2(Point _p,Point _d,int _mode=0):p1(_p),d(_d){
    if(_mode){
      p2=d;
      d=p2-p1;
    }else{
      p2=p1+d;
    }
  }
};

Point prj(ve2& l,Point& p){
  double t=dot(p-l.p1,l.d)/norm(l.d);
  return l.p1+l.d*t;
}
Point rfl(ve2& l,Point& p){return prj(l,p)*2-p;}
bool is_prll(ve2& a,ve2& b){return abs(cross(a.d,b.d))<eps;}
bool is_orth(ve2& a,ve2& b){return abs(dot(a.d,b.d))<eps;}
int ccw(ve2& a,ve2& b){
  double l1Xl2=cross(a.d,b.d);
  if(l1Xl2>eps)return 0;
  if(l1Xl2<-eps)return 1;
  ve2 va(b.p2,a.p1,1),vb(b.p2,a.p2,1);
  double ta=dot(va.d,a.d),tb=dot(vb.d,a.d);
  if(ta>eps&&tb>eps)return 2;
  if(ta<-eps&&tb<-eps)return 3;
  return 4;
}

int main(){
  ll n,m,c,b1,b2,b3;
  cin >> n >> m >> c;
  vector<set<pll>> gr(n);
  ri(m){
    cin >> b1 >> b2 >> b3;
    --b1;--b2;
    gr[b1].insert(pll(b2,b3));
  }
  vector<vll> bcost(n,vll(2,LNF));
  bcost[0][0]=0;
  priority_queue<tlll,vector<tlll>,greater<tlll>> dij;
  dij.push(tlll(0,0,0));
  while(dij.size()){
    tlll tmp=dij.top();
    ll ccost=get<0>(tmp);
    ll pos=get<1>(tmp);
    ll k=get<2>(tmp);
    dij.pop();
    if(bcost[pos][k]<ccost)continue;
    if(asr(pos-1,n))if(bcost[pos-1][k]>ccost+c){
      bcost[pos-1][k]=ccost+c;
      dij.push(tlll(ccost+c,pos-1,k));
    }
    if(asr(pos+1,n))if(bcost[pos+1][0]>ccost+c){
      bcost[pos+1][0]=ccost+c;
      dij.push(tlll(ccost+c,pos+1,0));
    }
    for(auto x:gr[pos])if(bcost[x.first][1]>ccost+x.second){
      bcost[x.first][1]=ccost+x.second;
      dij.push(tlll(ccost+x.second,x.first,1));
    }
  }
  ll ans=bcost[n-1][1];
  pr(ans!=LNF?ans:-1);
}
accuracy: 1
time_ms: 130
memory_kb: 33648
final_rank: 16

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

int main(){
	long long n,m,c;
	cin >> n >> m >> c;
	vector<vector<pair<long long,long long>>> g(n,vector<pair<long long,long long>>());
	for(long long i = 0ll;i < m;i++){
		long long u,v,x;
		cin >> u >> v >> x;
		u--;v--;
		g[v].push_back({u,x});
	}
	priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>> q;
	if(!g[n - 1ll].empty()){
		for(pair<long long,long long> i : g[n - 1ll]){
			q.push({i.second,i.first});
		}
	}
	vector<long long> ans(n,-1ll);
	while(!q.empty()){
		pair<long long,long long> it = q.top();
		q.pop();
		if(ans[it.second] != -1ll) continue;
		ans[it.second] = it.first;
		if(!g[it.second].empty()){
			for(pair<long long,long long> i : g[it.second]){
				if(ans[i.first] != -1ll) continue;
				q.push({it.first + i.second,i.first});
			}
		}
		if(it.second > 0ll && ans[it.second - 1ll] == -1ll){
			q.push({it.first + c,it.second - 1ll});
		}
		if(it.second < n - 1ll && ans[it.second + 1ll] == -1ll){
			q.push({it.first + c,it.second + 1ll});
		}
	}
	cout << ans[0ll] << endl;
}
accuracy: 1
time_ms: 70
memory_kb: 13172
final_rank: 6

code_snippet: #include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main()
{
  int n,m,C;
  cin >> n >> m >> C;
  vector<vector<pair<int,int>>>graph(n);
  for(int i=0;i<m;i++){
    int a,b,c;
    cin >> a >> b >> c;
    graph[a-1].push_back(make_pair(b,c));
  }
  //その地点への最小コスト、その地点のテレポート装置を使うための最小コスト
  vector<pair<long long,long long>>dist(n);
  for(int i=0;i<n;i++)dist[i]=make_pair(1e18,1e18);
  dist[0]=make_pair(0,0);
  priority_queue<pair<long long,pair<int,int>>,vector<pair<long long,pair<int,int>>>,greater<pair<long long,pair<int,int>>>>prq;
  prq.push(make_pair(0,make_pair(1,0)));
  prq.push(make_pair(0,make_pair(1,1)));
  while(prq.size()){
    pair<long long,pair<int,int>>hako=prq.top();
    prq.pop();
    //その地点への最小コストを見る
    if(hako.second.second==0){
      int a=hako.second.first;
      if(dist[a-1].first!=hako.first)continue;
      for(int i=0;i<graph[a-1].size();i++)if(dist[graph[a-1][i].first-1].first>dist[a-1].first+graph[a-1][i].second){
	  dist[graph[a-1][i].first-1].first=dist[a-1].first+graph[a-1][i].second;
	  prq.push(make_pair(dist[graph[a-1][i].first-1].first,make_pair(graph[a-1][i].first,0)));
	  if(dist[graph[a-1][i].first-1].second>dist[a-1].first+graph[a-1][i].second){
	    dist[graph[a-1][i].first-1].second=dist[a-1].first+graph[a-1][i].second;
	    prq.push(make_pair(dist[graph[a-1][i].first-1].second,make_pair(graph[a-1][i].first,1)));
	  }
	}
      //移動
      if(a>1 && dist[a-2].second>dist[a-1].first+C){
	dist[a-2].second=dist[a-1].first+C;
	prq.push(make_pair(dist[a-2].second,make_pair(a-1,1)));
      }
      if(a+1<n && dist[a].second>dist[a-1].first+C){
	dist[a].second=dist[a-1].first+C;
	prq.push(make_pair(dist[a].second,make_pair(a+1,1)));
      }
    }
    //その地点のテレポーターを使うための最小コストを見る
    else{
      int a=hako.second.first;
      if(dist[a-1].second!=hako.first)continue;
      for(int i=0;i<graph[a-1].size();i++)if(dist[graph[a-1][i].first-1].first>dist[a-1].second+graph[a-1][i].second){
	  dist[graph[a-1][i].first-1].first=dist[a-1].second+graph[a-1][i].second;
	  prq.push(make_pair(dist[graph[a-1][i].first-1].first,make_pair(graph[a-1][i].first,0)));
	  if(dist[graph[a-1][i].first-1].second>dist[a-1].second+graph[a-1][i].second){
	    dist[graph[a-1][i].first-1].second=dist[a-1].second+graph[a-1][i].second;
	    prq.push(make_pair(dist[graph[a-1][i].first-1].second,make_pair(graph[a-1][i].first,1)));
	  }
	}
      if(a>1 && dist[a-2].second>dist[a-1].second+C){
	dist[a-2].second=dist[a-1].second+C;
	prq.push(make_pair(dist[a-2].second,make_pair(a-1,1)));
      }
      if(a+1<=n && dist[a].second>dist[a-1].second+C){
	dist[a].second=dist[a-1].second+C;
	prq.push(make_pair(dist[a].second,make_pair(a+1,1)));
      }
    }
  }
  if(dist[n-1].first==1e18)cout << -1 << endl;
  else cout << dist[n-1].first << endl;
}
accuracy: 1
time_ms: 80
memory_kb: 14400
final_rank: 7

code_snippet: #include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main()
{
  int n,m,C;
  cin >> n >> m >> C;
  vector<vector<pair<int,int>>>graph(n);
  for(int i=0;i<m;i++){
    int a,b,c;
    cin >> a >> b >> c;
    graph[a-1].push_back(make_pair(b,c));
  }
  //その地点への最小コスト、その地点のテレポート装置を使うための最小コスト
  vector<pair<long long,long long>>dist(n);
  for(int i=0;i<n;i++)dist[i]=make_pair(1e18,1e18);
  dist[0]=make_pair(0,0);
  priority_queue<pair<long long,pair<int,int>>,vector<pair<long long,pair<int,int>>>,greater<pair<long long,pair<int,int>>>>prq;
  prq.push(make_pair(0,make_pair(1,0)));
  prq.push(make_pair(0,make_pair(1,1)));
  while(prq.size()){
    pair<long long,pair<int,int>>hako=prq.top();
    prq.pop();
    //その地点への最小コストを見る
    if(hako.second.second==0){
      int a=hako.second.first;
      if(dist[a-1].first!=hako.first)continue;
      for(int i=0;i<graph[a-1].size();i++)if(dist[graph[a-1][i].first-1].first>dist[a-1].first+graph[a-1][i].second){
	  dist[graph[a-1][i].first-1].first=dist[a-1].first+graph[a-1][i].second;
	  prq.push(make_pair(dist[graph[a-1][i].first-1].first,make_pair(graph[a-1][i].first,0)));
	  if(dist[graph[a-1][i].first-1].second>dist[a-1].first+graph[a-1][i].second){
	    dist[graph[a-1][i].first-1].second=dist[a-1].first+graph[a-1][i].second;
	    prq.push(make_pair(dist[graph[a-1][i].first-1].second,make_pair(graph[a-1][i].first,1)));
	  }
	}
      //移動
      if(a>1 && dist[a-2].second>dist[a-1].first+C){
	dist[a-2].second=dist[a-1].first+C;
	prq.push(make_pair(dist[a-2].second,make_pair(a-1,1)));
      }
      if(a+1<n && dist[a].second>dist[a-1].first+C){
	dist[a].second=dist[a-1].first+C;
	prq.push(make_pair(dist[a].second,make_pair(a+1,1)));
      }
    }
    //その地点のテレポーターを使うための最小コストを見る
    else{
      int a=hako.second.first;
      if(dist[a-1].second!=hako.first)continue;
      for(int i=0;i<graph[a-1].size();i++)if(dist[graph[a-1][i].first-1].first>dist[a-1].second+graph[a-1][i].second){
	  dist[graph[a-1][i].first-1].first=dist[a-1].second+graph[a-1][i].second;
	  prq.push(make_pair(dist[graph[a-1][i].first-1].first,make_pair(graph[a-1][i].first,0)));
	  if(dist[graph[a-1][i].first-1].second>dist[a-1].second+graph[a-1][i].second){
	    dist[graph[a-1][i].first-1].second=dist[a-1].second+graph[a-1][i].second;
	    prq.push(make_pair(dist[graph[a-1][i].first-1].second,make_pair(graph[a-1][i].first,1)));
	  }
	}
      if(a>1 && dist[a-2].second>dist[a-1].second+C){
	dist[a-2].second=dist[a-1].second+C;
	prq.push(make_pair(dist[a-2].second,make_pair(a-1,1)));
      }
      if(a+1<=n && dist[a].second>dist[a-1].second+C){
	dist[a].second=dist[a-1].second+C;
	prq.push(make_pair(dist[a].second,make_pair(a+1,1)));
      }
    }
  }
  if(dist[n-1].first==1e18)cout << -1 << endl;
  else cout << dist[n-1].first << endl;
}
accuracy: 1
time_ms: 80
memory_kb: 14436
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct edge{
  ll cost;
  ll u;
  bool isu;
};
bool operator< (const edge &e, const edge &f){
    return e.cost > f.cost;
};
int main(){
  ll N,M,C;
  cin >> N >> M >> C;
  vector<vector<pair<ll,ll>>> G(N);
  for(int i=0;i<M;i++){
    ll a,b,f;
    cin >> a >> b >> f;
    a--;
    b--;
    G[b].push_back(pair(a,f));
  }
  priority_queue<edge,vector<edge>> pq;
  vector<ll> dp(N,1e18);
  vector<bool> isu(N,false);
  dp[N-1] = 0;
  pq.push({dp[N-1],N-1,false});
  while(pq.size()>0){
    edge e = pq.top();
    pq.pop();
    if(e.cost!=dp[e.u]) continue;
    for(pair<ll,ll> p:G[e.u]){
      ll v = p.first;
      ll cost = p.second;
      if(isu[v]==false){
        dp[v] = e.cost+cost;
        isu[v] = true;
        pq.push({dp[v],v,true});
      }else{
        if(dp[v]>e.cost+cost){
          dp[v] = e.cost+cost;
          pq.push({dp[v],v,true});
        }
      }
    }
    if(e.isu){
      if(e.u>0){
        if(isu[e.u-1]==false){
          dp[e.u-1] = dp[e.u]+C;
          isu[e.u-1] = true;
          pq.push({dp[e.u-1],e.u-1,true});
        }else{
          if(dp[e.u-1]>dp[e.u]+C){
            dp[e.u-1] = dp[e.u]+C;
            pq.push({dp[e.u-1],e.u-1,true});
          }
        }
      }
      if(e.u<N-1){
        if(isu[e.u+1]==false){
          dp[e.u+1] = dp[e.u]+C;
          isu[e.u+1] = true;
          pq.push({dp[e.u+1],e.u+1,true});
        }else{
          if(dp[e.u+1]>dp[e.u]+C){
            dp[e.u+1] = dp[e.u]+C;
            pq.push({dp[e.u+1],e.u+1,true});
          }
        }
      }
    }
  }
  cout << ((dp[0]==1e18) ? -1:dp[0]) << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 13908
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i = a; i < n; i++)
#define yes (cout << "Yes" << endl)
#define YES (cout << "YES" << endl)
#define no (cout << "No" << endl)
#define NO (cout << "NO" << endl)
#define dame (cout << -1 << endl)
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define all(a)  (a).begin(),(a).end()
#define ll long long
#define pll pair<long long,long long>
#define pq priority_queue
#define vl vector<long long> 
template<typename T,typename U>
inline constexpr bool chmin(T&a,const U&b){return (a>b?a=b,true:false);}
template<typename T,typename U>
inline constexpr bool chmax(T&a,const U&b){return (a<b?a=b,true:false);}

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
//DRUL
using namespace std;

int main() {
    ll n,m,c;
    cin >> n >> m >> c;
    vector<ll> a(m),b(m),f(m);
    rep(i,0,m) {
        cin >> a[i] >> b[i] >> f[i];
        a[i]--;
        b[i]--;
    }
    vector<vector<pair<ll,ll>>> e(n * 2);
    rep(i,0,n) {
        e[i].pb({0,n + i});
    }
    rep(i,0,n - 1) {
        e[n + i].pb({c,n + i + 1});
        e[n + i + 1].pb({c,n + i});
    }
    
    rep(i,0,m) {
        e[n + a[i]].pb({f[i],b[i]});
    }
    vl dist(n * 2,-1);
    pq<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> q;
    q.push({0,0});
    while(!q.empty()) {
        ll c,v;
        tie(c,v) = q.top();
        q.pop();
        if(dist[v] == -1) {
            dist[v] = c;
            for(auto t : e[v]) {
                ll w = t.second;
                if(dist[w] == -1) {
                    q.push({t.first  + c,w});
                }
            }
        }
    }
    
    //rep(i,0,n * 2) cout << dist[i] << endl;
    
    cout << dist[n - 1] << endl;
    
}
accuracy: 1
time_ms: 130
memory_kb: 39112
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Edge {
	int to;
	int cost;
};
using Graph = vector<vector<Edge>>;
int cast(int x, int y) {
	return (2 * x) + y;
}
void DJK(Graph& G, vector<ll>& dist, int st) {
	dist[st] = 0;
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
	pq.push({0, st});
	while (!pq.empty()) {
		ll d = pq.top().first;int v = pq.top().second;
		pq.pop();
		if (dist[v] < d) continue;
		for (auto nv : G[v]) {
			ll nd = d + nv.cost;
			if (dist[nv.to] < nd) continue;
			dist[nv.to] = nd;
			pq.push({nd, nv.to});
		}
	}
}
int main() {
	int N, M, C;cin >> N >> M >> C;
	Graph G(2 * N);
	for (int i = 0;i < M;i++) {
		int a, b, f;cin >> a >> b >> f;
		a--;b--;
		G[cast(a, 0)].push_back({cast(b, 1), f});
	}
	for (int v = 0;v < N;v++) {
		G[cast(v, 1)].push_back({cast(v, 0), 0});
		if (v + 1 == N) continue;
		G[cast(v, 0)].push_back({cast(v + 1, 0), C});
		G[cast(v + 1, 0)].push_back({cast(v, 0), C});
	}
	ll INF =  (1LL << 60);
	vector<ll> dist(2 * N, INF);
	DJK(G, dist, cast(0, 1));
	ll ret = dist[cast(N - 1, 1)];
	if (ret == INF) {
		cout << -1 << endl;
	} else {
		cout << ret << endl;
	}
}
accuracy: 1
time_ms: 120
memory_kb: 30328
final_rank: 15

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

#ifdef LOCAL
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif

const int INF = (1 << 30) - 1;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N, M, C;
    cin >> N >> M >> C;
    // テレポーターに関するグラフを貼る
    vector<vector<tuple<int, int, int>>> G(N);
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c, a--, b--;
        G[a].emplace_back(b, c, 0);
    }
    // テレポーターを移動するのではなく自分を移動させる
    // テレポーターを -1 移動する -> 自分を +1 移動すると等しい
    for (int i = 0; i < N; i++) {
        if (i + 1 < N) G[i].emplace_back(i + 1, C, 1);
        if (i - 1 >= 0) G[i].emplace_back(i - 1, C, 1);
    }

    // dijkstra
    // dist[i][j] := 地点 i に (j = 0: テレポート, j = 1: 移動) で到達する最小コスト
    vector dist(N, vector<int>(2, INF));
    priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> que;
    dist[0][0] = 0;
    que.emplace(dist[0][0], 0, 0);
    while (!que.empty()) {
        auto [cost, from, type] = que.top();
        que.pop();
        if (dist[from][type] < cost) continue;
        for (auto&& [to, c, new_type] : G[from]) {
            int new_cost = cost + c;
            if (dist[to][new_type] > new_cost) {
                dist[to][new_type] = new_cost;
                que.emplace(dist[to][new_type], to, new_type);
            }
        }
    }

    debug(dist);
    cout << (dist[N - 1][0] == INF ? -1 : dist[N - 1][0]) << '\n';
}
accuracy: 1
time_ms: 90
memory_kb: 28392
final_rank: 13