Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
//	"strings"
    "sort"
//    "container/heap"
)

/*********** Input **************/
/*
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}*/

func scanInt(sc *bufio.Scanner) int {
    sc.Scan()
    v, _ := strconv.Atoi(sc.Text())
    return v
}
/**************  End Input  **************/

func toInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

type Edge struct {
	to      int
	newTime int
}

type State struct {
	node int
	time int
}


/**************  Cell  *****************/

type Cell struct {
	item *State
	next *Cell
}

func NewCell(x *State, cp *Cell) *Cell {
	newCp := new(Cell)
	newCp.item = x
	newCp.next = cp
	return newCp
}

/************  End Cell  ***************/

/**************  Queue  ****************/

type Queue struct {
	size  int
	front *Cell
	rear  *Cell
}

func NewQue() *Queue {
	return new(Queue)
}

func (q *Queue) Push(x *State) {
	newNode := NewCell(x, nil)
	if q.size == 0 {
		q.front = newNode
		q.rear = newNode
	} else {
		q.rear.next = newNode
		q.rear = newNode
	}
	q.size++
}

func (q *Queue) PopLeft() (*State, bool) {
	if q.size == 0 {
		return nil, false
	} else {
		x := q.front.item
		q.front = q.front.next
		q.size--
		if q.size == 0 {
			q.rear = nil
		}
		return x, true
	}
}

func (q *Queue) IsEmpty() bool {
	return q.size == 0
}

/***********  end Queue  ***********/

type EdgeSorter struct {
    edges []Edge
    lessfunc []lessFunc
    used int
    length int
}

type lessFunc func(i, j *Edge)bool

func (ES EdgeSorter) Len() int {
    return len(ES.edges)
}

func (ES EdgeSorter) Swap(i, j int) {
    ES.edges[i], ES.edges[j] = ES.edges[j], ES.edges[i]
}

func (ES EdgeSorter) Less(i, j int) bool {
    var k int
    p, q := &ES.edges[i], &ES.edges[j]
    for k=0; k<len(ES.lessfunc)-1;k++ {
        less := ES.lessfunc[k]
        switch {
            case less(p, q):
                return true
            case less(q, p):
                return false
        }
    }
    return ES.lessfunc[k](p, q)
}

/*********** PriorityQueue ***********/
/*
type PriorityQueue struct {
    arr []*State
    size int
}

func (pq PriorityQueue) Len() int {
    return len(pq.arr)
}

func (pq PriorityQueue) Swap(i, j int) {
    pq.arr[i], pq.arr[j] = pq.arr[j], pq.arr[i]
}

func (pq PriorityQueue) Less(i, j int) bool{
    return pq.arr[i].time < pq.arr[j].time
}

func (pq *PriorityQueue) Push(x interface{}) {
    item := x.(*State)
    pq.arr = append(pq.arr, item)
    pq.size++
}

func (pq *PriorityQueue) Pop() interface{} {
    n := pq.size
    item := pq.arr[n - 1]
    pq.arr = pq.arr[:n - 1]
    pq.size--
    return item
}
*/


func main() {
    sc := bufio.NewScanner(os.Stdin)
    sc.Split(bufio.ScanWords)
	n, m := scanInt(sc), scanInt(sc)
	edges := make([]EdgeSorter, 0)
	for i := 0; i < n; i++ {
		edges = append(edges, EdgeSorter{})
	}
	for i := 0; i < m; i++ {
        a, b, c := scanInt(sc) - 1, scanInt(sc) - 1, scanInt(sc)
		edges[a].edges = append(edges[a].edges, Edge{to: b, newTime: c})
	}

    byNewTime := func(p1 *Edge, p2 *Edge) bool{
        return p1.newTime >= p2.newTime
    }

    for i, _ := range edges {
        v := &edges[i]
        v.lessfunc = append(v.lessfunc, byNewTime)
        sort.Sort(v)
        v.used = 0
        v.length = len(v.edges)
    }
    var minTime [100000]int
    for i := 0; i < n; i++ {
        minTime[i] = 2000000000
    }
    minTime[0] = 0
    que := Queue{}
    que.Push(&State{node: 0, time: 0})
	ans := -1
	for !que.IsEmpty() {
		state, _ := que.PopLeft()
		for edges[state.node].used < edges[state.node].length {
            e := edges[state.node].edges[edges[state.node].used]
			if e.newTime >= state.time {
                if e.to == n - 1 && e.newTime > ans {
                    ans = e.newTime
             

Python: from collections import deque

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    edges[a - 1].append((b - 1, c))

que = deque()
que.append((0, 0))
ans = -1
while que:
    pos, time = que.popleft()
    if pos == n - 1:
        ans = max(ans, time)
    for i in range(len(edges[pos]) - 1, -1, -1):
        to, new_time = edges[pos][i]
        if new_time >= time:
            que.append((to, new_time))
            edges[pos].pop(i)
print(ans)

Python: # AOJ 590: One-Time Path
# Python3 2018.7.13 bal4u

INF = 0x7fffffff
import heapq
def dijkstra(V, to, start):
	dist = [INF]*V
	Q = []
	dist[start] = 0
	heapq.heappush(Q, (0, start))
	while Q:
		t, s = heapq.heappop(Q)
		if dist[s] < t: continue
		for e, cost in to[s]:
			if t <= cost and cost < dist[e]:
				dist[e] = cost
				heapq.heappush(Q, (cost, e))
	return dist

n, m = map(int, input().split())
n1 = n - 1
last = []
to = [[] for i in range(n)]
for i in range(m):
	a, b, c = map(int, input().split())
	a -= 1; b -= 1
	to[a].append((b, c))
	if b == n-1: last.append((a, c))

dist = dijkstra(n, to, 0)
if dist[n-1] >= INF: print(-1)
else:
	last.sort(key=lambda x:(-x[1]))
	for a, c in last:
		if dist[a] <= c: print(c); break

C++: #include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N; int M;
	while(~scanf("%d%d", &N, &M)) {
		vector<vpii> g(N);
		rep(i, M) {
			int a; int b; int c;
			scanf("%d%d%d", &a, &b, &c), -- a, -- b;
			g[a].emplace_back(b, c);
		}
		int ans = -1;
		vector<bool> vis(N);
		priority_queue<pii,vpii,greater<pii>> pq;
		pq.push(make_pair(0, 0));
		while(!pq.empty()) {
			int t = pq.top().first;
			int i = pq.top().second;
			pq.pop();
			if(vis[i]) continue;
			vis[i] = true;
			for(auto e : g[i]) if(t <= e.second) {
				if(e.first == N - 1) {
					amax(ans, e.second);
				} else {
					pq.push(make_pair(e.second, e.first));
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;


int main() {
	int N,M;cin>>N>>M;
	vector<vector<pair<int,int>>>edges(N);
	vector<int>memo(N-1,1e9+1e7);
	memo[0]=0;

	for (int i = 0; i < M; ++i) {
		int a,b,c;cin>>a>>b>>c;
		a--;b--;
		edges[a].push_back(make_pair(b,c));
	}

	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>que;
	que.push(make_pair(0,0));
	while (!que.empty()) {
		auto atop(que.top());
		que.pop();
		const int now=atop.second;
		const int now_time=atop.first;
		for (auto e : edges[now]) {
			if(e.first==N-1)continue;
			if (e.second >= now_time) {
				if (memo[e.first] > e.second) {
					que.push(make_pair(e.second,e.first));
					memo[e.first]=e.second;
				}
			}
		}
	}

	int ans=-1;
	for (int i = 0; i < N - 1; ++i) {
		for (auto e : edges[i]) {
			if (e.first==N-1&&memo[i] <= e.second) {
				ans=max(ans,e.second);
			}
		}
	}
	{
		cout<<ans<<endl;
	}
	return 0;
}