Language: C++

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

using Weight=int;
const Weight INF=1e9;
enum{SAME,ASC,DES};
struct Edge{
    int to;
    Weight cost;
    int label;
};

using Edges=vector<Edge>;
using Graph=vector<Edges>;
priority_queue<pair<Weight,int>,vector<pair<Weight,int>>,greater<>> que;
vector<int> used(50*50*(1<<10));

void dijkstra(int s,Graph& g,array<Weight> &d){
    d[s]=0;
    assert(que.empty());

    fill(used.begin(),used.end(),0);
    que.push(make_pair(Weight(0),s));
    //cerr<<"####"<<endl;
    while(!que.empty()){
        auto ret=que.top(); que.pop();
        int v=ret.second;
        //cerr<<v/3/(1<<10)<<" "<<(v/(1<<10)%3)<<" "<<bitset<10>(v&((1<<10)-1))<<endl;
        if(used[v]) continue;
        used[v]=true;
        for(int i=0;i<g[v].size();i++){
            int to=g[v][i].to;
            //cerr<<"to"<<to/3<<" "<<to%3<<endl;
            Weight w=g[v][i].cost+d[v];
            if(w<d[to] && !used[to]){
                d[to]=w;
                que.push(make_pair(w,to));
            }
        }
    }
    return;
}

int vertex(int i,int j,int mask,int n){
    return i*n*(1<<10)+j*(1<<10)+mask;
}

array<Weight,50*50*(1<<10)> dd;

Weight solve(int n,int m,vector<Weight>& d,vector<Weight>& e,const Graph &g){
    map<int,vector<int>> em;
    for(int i=0;i<n;i++){
        em[e[i]].push_back(i);
    }
    map<int,int> posmap;
    for(auto &e:em){
        for(int i=0;i<e.second.size();i++){
            posmap[e.second[i]]=i;
        }
    }
    Graph graph(n*n*(1<<10));    
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int l=0;l<(1<<10);l++){
                if(e[i]==e[j]){
                    if(!(l & (1<<posmap[i]))){
                        graph[vertex(i,j,l,n)].push_back(Edge{vertex(i,j,(l|(1<<posmap[i])),n),Weight(0),SAME});
                    }
                    else{
                        graph[vertex(i,j,l,n)].push_back(Edge{vertex(i,j,(l^(1<<posmap[i])),n),Weight(0),SAME});
                    }
                    if(!(l & (1<<posmap[j]))){
                        graph[vertex(i,j,l,n)].push_back(Edge{vertex(i,j,(l|(1<<posmap[j])),n),Weight(0),SAME});
                    }
                    else{
                        graph[vertex(i,j,l,n)].push_back(Edge{vertex(i,j,(l^(1<<posmap[j])),n),Weight(0),SAME});
                    }                    
                }
                for(int k=0;k<g[i].size();k++){
                    if(g[i][k].label==DES) continue;
                    int toMask=l;
                    if(g[i][k].label==ASC && l!=0) continue;
                    Weight w=g[i][k].cost+d[g[i][k].to];
                    if(j==g[i][k].to || (toMask & (1<<posmap[g[i][k].to]))){
                        w-=d[g[i][k].to];
                    }
                    graph[vertex(i,j,l,n)].push_back(Edge{vertex(g[i][k].to,j,toMask,n),w,g[i][k].label});
                }
                for(int k=0;k<g[j].size();k++){
                    if(g[j][k].label==ASC) continue;
                    int toMask=l;
                    if(g[j][k].label==DES && l!=0) continue;
                    Weight w=g[j][k].cost+d[g[j][k].to];
                    if(i==g[j][k].to || (toMask & (1<<posmap[g[j][k].to]))){
                        w-=d[g[j][k].to];
                    }
                    graph[vertex(i,j,l,n)].push_back(Edge{vertex(i,g[j][k].to,toMask,n),w,g[j][k].label});
                }
            }
        }
    }
    
    fill(dd.begin(),dd.end(),INF);
    dijkstra(vertex(0,0,0,n),graph,dd);
    return dd[vertex(n-1,n-1,0,n)];
}

int main(){
    int n,m;
    while(cin>>n>>m,n){
        vector<Weight> d(n);
        vector<Weight> e(n);
        d[0]=0;
        e[0]=0;
        for(int i=0;i<n-2;i++){
            cin>>d[i+1]>>e[i+1];
        }
        d[n-1]=0;
        e[n-1]=1000;
        Graph g(n);
        for(int i=0;i<m;i++){
            int a,b,c;
            cin>>a>>b>>c;
            a--,b--;
            if(e[a]<e[b]) g[a].push_back(Edge{b,c,ASC});
            else if(e[a]>e[b]) g[b].push_back(Edge{a,c,DES});
            else{
                g[a].push_back(Edge{b,c,SAME});
                g[b].push_back(Edge{a,c,SAME});
            }
        }
        auto ret=solve(n,m,d,e,g);
        cout<<(ret>=INF ? Weight(-1) : ret)<<endl;
    }

    return 0;
}


Compiler output:
a.cc:18:42: error: wrong number of template arguments (1, should be 2)
   18 | void dijkstra(int s,Graph& g,array<Weight> &d){
      |                                          ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:99:12: note: provided for 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc: In function 'void dijkstra(int, Graph&, int&)':
a.cc:19:6: error: invalid types 'int[int]' for array subscript
   19 |     d[s]=0;
      |      ^
a.cc:34:36: error: invalid types 'int[int]' for array subscript
   34 |             Weight w=g[v][i].cost+d[v];
      |                                    ^
a.cc:35:19: error: invalid types 'int[int]' for array subscript
   35 |             if(w<d[to] && !used[to]){
      |                   ^
a.cc:36:18: error: invalid types 'int[int]' for array subscript
   36 |                 d[to]=w;
      |                  ^
a.cc: In function 'Weight solve(int, int, std::vector<int>&, std::vector<int>&, const Graph&)':
a.cc:104:36: error: invalid initialization of reference of type 'int&' from expression of type 'std::array<int, 2560000>'
  104 |     dijkstra(vertex(0,0,0,n),graph,dd);
      |                                    ^~
a.cc:18:45: note: in passing argument 3 of 'void dijkstra(int, Graph&, int&)'
   18 | void dijkstra(int s,Graph& g,array<Weight> &d){
      |                              ~~~~~~~~~~~~~~~^