Language: C++

#include <bits/stdc++.h>
 
using namespace std;
 
template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}
 
template<class W>
struct edge{
	int from, to;
	W weight;
	edge(int from, int to, W weight):from(from), to(to), weight(weight){}
};
template<class W> using node = vector<edge<W>>;
template<class W> using graph = vector<node<W>>;
template<class W> void addedge(graph<W> &g, int from, int to, W weight, bool bidirectional = false){
	g[from].emplace_back(edge<W>(from, to, weight));
	if(bidirectional)g[to].emplace_back(edge<W>(to, from, weight));
}
 
 
class Solution {
public:
	void solve() {
		using pii = pair<int, int>;
		int n, m, l;
		cin >> n >> m >> l;
		graph<int> g(n);
		vector<vector<int>> d(n, vector<int>(n, 0x3f3f3f3f));
		for(int i=0; i < m; i++){
			int a, b, c;
			cin >> a >> b >> c;
			
			addedge(g, a-1, b-1, c, true);
		}
		for(int i=0; i < n; i++){
			priority_queue<pii> q;
			vector<int> r(n, -1);
			q.push(make_pair(l, i));
			r[i] = l;
			while(!q.empty()){
				int rem, node;
				tie(rem, node) = q.top();
				q.pop();
				d[i][node] = 1;
				for(auto e: g[node]){
					if(r[e.to] < rem - e.weight){
						q.push(make_pair(rem-e.weight, e.to));
						r[e.to] = rem-e.weight;
					}
				}
			}
		}
		for(int k=0; k < n; k++){
			for(int i=0; i < n; i++){
				for(int j=0; j < n; j++){
					updmin(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
 
		int Q;
		cin >> Q;
		for(int q=0; q < Q; q++){
			int s, t;
			cin >> s >> t;
			if(d[s-1][t-1] == 0x3f3f3f3f)cout << -1 << "\n";
			else cout << d[s-1][t-1]-1 << "\n";				
		}
 
	
		return;
	};
};
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}
#include <bits/stdc++.h>

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

template<class W>
struct edge{
	int from, to;
	W weight;
	edge(int from, int to, W weight):from(from), to(to), weight(weight){}
};
template<class W> using node = vector<edge<W>>;
template<class W> using graph = vector<node<W>>;
template<class W> void addedge(graph<W> &g, int from, int to, W weight, bool bidirectional = false){
	g[from].emplace_back(edge<W>(from, to, weight));
	if(bidirectional)g[to].emplace_back(edge<W>(to, from, weight));
}


class Solution {
public:
	void solve() {
		using pii = pair<int, int>;
		int n, m, l;
		cin >> n >> m >> l;
		graph<int> g(n);
		vector<vector<int>> d(n, vector<int>(n, 0x3f3f3f3f));
		for(int i=0; i < m; i++){
			int a, b, c;
			cin >> a >> b >> c;
			
			addedge(g, a-1, b-1, c, true);
		}
		for(int i=0; i < n; i++){
			priority_queue<pii> q;
			vector<int> r(n, -1);
			q.push(make_pair(l, i));
			r[i] = l;
			while(!q.empty()){
				int rem, node;
				tie(rem, node) = q.top();
				q.pop();
				d[i][node] = 1;
				for(auto e: g[node]){
					if(r[e.to] < rem - e.weight){
						q.push(make_pair(rem-e.weight, e.to));
						r[e.to] = rem-e.weight;
					}
				}
			}
		}
		for(int k=0; k < n; k++){
			for(int i=0; i < n; i++){
				for(int j=0; j < n; j++){
					updmin(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}

		int Q;
		cin >> Q;
		for(int q=0; q < Q; q++){
			int s, t;
			cin >> s >> t;
			if(d[s-1][t-1] == 0x3f3f3f3f)cout << -1 << "\n";
			else cout << d[s-1][t-1]-1 << "\n";				
		}

	
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}
提出情報
提出日時

Compiler output:
a.cc:87:28: error: redefinition of 'template<class T> T updmax(T&, T)'
   87 | template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
      |                            ^~~~~~
a.cc:5:28: note: 'template<class T> T updmax(T&, T)' previously declared here
    5 | template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
      |                            ^~~~~~
a.cc:88:28: error: redefinition of 'template<class T> T updmin(T&, T)'
   88 | template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}
      |                            ^~~~~~
a.cc:6:28: note: 'template<class T> T updmin(T&, T)' previously declared here
    6 | template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}
      |                            ^~~~~~
a.cc:91:8: error: redefinition of 'struct edge<W>'
   91 | struct edge{
      |        ^~~~
a.cc:9:8: note: previous definition of 'struct edge<W>'
    9 | struct edge{
      |        ^~~~
a.cc:98:24: error: redefinition of 'template<class W> void addedge(graph<W>&, int, int, W, bool)'
   98 | template<class W> void addedge(graph<W> &g, int from, int to, W weight, bool bidirectional = false){
      |                        ^~~~~~~
a.cc:16:24: note: 'template<class W> void addedge(graph<W>&, int, int, W, bool)' previously declared here
   16 | template<class W> void addedge(graph<W> &g, int from, int to, W weight, bool bidirectional = false){
      |                        ^~~~~~~
a.cc:104:7: error: redefinition of 'class Solution'
  104 | class Solution {
      |       ^~~~~~~~
a.cc:22:7: note: previous definition of 'class Solution'
   22 | class Solution {
      |       ^~~~~~~~
a.cc:158:5: error: redefinition of 'int main()'
  158 | int main() {
      |     ^~~~
a.cc:76:5: note: 'int main()' previously defined here
   76 | int main() {
      |     ^~~~
a.cc:165:1: error: '\U000063d0\U000051fa\U000060c5\U00005831' does not name a type
  165 | 提出情報
      | ^~~~~~~~