Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <deque>

using namespace std;

struct Edge{
	unsigned u, v, dist;
	bool operator == (const Edge &e){ return (u == e.u && v == e.v) || (u == e.v && v == e.u); }
	bool operator != (const Edge &e){ return !(*this == e); }
	bool operator < (const Edge &e) const { return u < e.u || (u == e.u && v < e.v); }
};

ostream & operator << (ostream &dest, const Edge &e){
	dest << "(" << e.u << ", " << e.v << ") : " << e.dist;
	return dest;
}

struct Graph{
	unsigned V, E;
	vector<unsigned> dist;
	vector<unsigned> col;
	vector<unsigned> row;
	

	Graph() : V(get_unsigned()), E(get_unsigned()), dist(2*E), col(2*E), row(V + 1)	
	{
		vector<Edge> edges(2*E);
		for(unsigned i = 0; i < E; ++i){
			cin >> edges[i].u >> edges[i].v >> edges[i].dist;
			edges[i + E].u = edges[i].v;
			edges[i + E].v = edges[i].u;
			edges[i + E].dist = edges[i].dist;
		}
		sort(edges.begin(), edges.end());
		size_t r = 0;
		for(size_t i = 0; i < 2*E; ++i){
			while(r != edges[i].u) row[r++] = i;
			col[i] = edges[i].v;
			dist[i] = edges[i].dist;
		}
		for(; r <= V; ++r)
			row[r] = 2*E;
	}

	unsigned distance(size_t i, size_t j) const{
		size_t I = min(i, j);
		size_t J = max(i, j);
		if(I == 0) return 0;
		for(size_t k = row[I - 1]; k < row[I]; ++k)
			if(J == col[k]) return dist[k];
		return 0;
	}
	unsigned neighbor_begin(size_t i) const{
		if(i == 0) return -1;
		return row[i - 1];
	}
	unsigned neighbor_end(size_t i) const{
		if(i == 0) return -1;
		return row[i];
	}

private:
	unsigned get_unsigned() const{
		unsigned tmp; cin >> tmp;
		return tmp;
	}
};

void WF(const Graph &G, vector<vector<unsigned>> &next, vector<vector<unsigned>> &distance){
	
	for(size_t from = 0; from < G.V; ++from){
		for(size_t to = 0; to < G.V; ++to){
			distance[from][to] = from == to ? 0 : 1'000'000'000;
			next[from][to] = from;
		}
	}
	for(size_t from = 0; from < G.V; ++from){
		for(size_t to_index = G.neighbor_begin(from+ 1); to_index < G.neighbor_end(from + 1); ++to_index){
			size_t to = G.col[to_index] - 1;
			distance[from][to] = G.dist[to_index];
			next[from][to] = to;
		}
	}
	for(size_t inter = 0; inter < G.V; ++inter){
		for(size_t from = 0; from < G.V; ++from){
			for(size_t to = 0; to < G.V; ++to){
				if(distance[from][to] > distance[from][inter] + distance[inter][to]){
					distance[from][to] = distance[from][inter] + distance[inter][to];
					next[from][to] = next[from][inter];
				}
			}
		}
	}
}


int main(){
	Graph G;
	unsigned T_max;
	cin >> T_max;
	vector<unsigned> orders(T_max);
	for(unsigned t = 0; t < T_max; ++t){
		unsigned N_new;
		cin >> N_new;
		if(N_new == 0) orders[t] = 0;
		else{
			unsigned id;
			cin >> id >> orders[t];
		}
	}

	vector<vector<unsigned>> distance(G.V, vector<unsigned>(G.V));
	vector<vector<unsigned>> next(G.V, vector<unsigned>(G.V));

	WF(G, next, distance);

	auto put_command = [T_max](int command){
		static size_t line = 0;
		if(line++ == T_max) exit(0);
		cout << command << "\n";
	};

	auto move = [&](size_t from, size_t to, deque<pair<unsigned, unsigned>> &load){
		size_t t = 0;
		size_t current = from;
		size_t next_point = next[current][to];
		size_t distance_to_next = distance[current][next_point];
		while(current != to){
			for(size_t way = 0; way < distance_to_next; ++way)
				++t, put_command(next_point + 1);
			current = next_point;
			next_point = next[current][to];
			distance_to_next = distance[current][next_point];
			load.erase(remove_if(load.begin(), load.end(), [current](auto &p){return p.second == current;}), load.end());
		}
		return t;
	};

	size_t t = 0;
	size_t elapsed = 0;

	deque<pair<unsigned, unsigned>> loading;
	size_t current = 0;
	bool is_moving = false;
	size_t goal = 0;
	size_t last_load = 0;

	if(!orders[0]) put_command(-1);
	while(1){
		for(size_t i = last_load + 1; i < t; ++i)
			if(orders[i]) last_load = i, loading.emplace_back(make_pair(i, orders[i] - 1));
		if(loading.empty()){
			while(!orders[++t])
				put_command(-1);
			loading.emplace_back(make_pair(t, orders[t] - 1));
			last_load = t;
		}

		while(!loading.empty()){
			goal = loading.begin()->second;
			loading.pop_front();
			//cout << "t : " << t << ", goal : " << goal << endl; 
			t += move(current, goal, loading);
			current = goal;
		}
		t += move(current, 0, loading);
		current = 0;
	}
	return 0;
}


Compiler output:
a.cc: In constructor 'Graph::Graph()':
a.cc:37:17: error: 'sort' was not declared in this scope; did you mean 'short'?
   37 |                 sort(edges.begin(), edges.end());
      |                 ^~~~
      |                 short
a.cc: In lambda function:
a.cc:137:36: error: 'remove_if' was not declared in this scope; did you mean 'remove'?
  137 |                         load.erase(remove_if(load.begin(), load.end(), [current](auto &p){return p.second == current;}), load.end());
      |                                    ^~~~~~~~~
      |                                    remove