Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- # define vt vector
- # define pque priority_queue
- typedef long long ll;typedef long double lld;typedef string str;typedef pair<double, double> dd;
- typedef vt<int> vi;typedef vt<vt<int>> vvi;typedef vt<double> vd;typedef vt<ll> vll;typedef pair<int,int> ii;
- typedef vt<lld> vld;typedef vt<char> vc;typedef vt<str> vs;typedef vt<ii> vii;typedef vt<vii> vvii;
- # define f(i,a,b,c) for(ll i=a;i<b;i+=c)
- # define fd(i,a,b,c) for(ll i=a;i>=b;i-=c)
- # define w(x) while(x--)
- # define ctoi(a) (a-'0')
- # define pb push_back
- # define eb emplace_back
- # define lb lower_bound
- # define ub upper_bound
- # define ts to_string
- # define len(x) x.length()
- # define be(x) x.begin(), x.end()
- # define rbe(x) x.rbegin(), x.rend()
- # define bb(x, y) binary_search(be(x), y)
- # define _(x) cout.precision(x);cout.setf(ios::fixed);
- # define ft first
- # define se second
- # define mdc(a, b) __gcd(a, b)
- # define esq(x) x*2
- # define dir(x) x*2+1
- const int MAX = 1e3+1, mV = 1<<20, mM = 105, INF = 0x3f3f3f3f, OUT = -INF;
- int n, m, p;
- int dist[mM][mM][mM];
- int u, v, w;
- void fw(){
- f(k,1,n+1,1)
- f(i,1,n+1,1)
- f(j,1,n+1,1)
- dist[k][i][j] = min(dist[k-1][i][j],dist[k-1][i][k]+dist[k-1][k][j]);
- }
- int main(){_(0)
- while(cin>>n>>m){
- f(i,0,n+1,1)
- f(j,0,n+1,1)
- dist[0][i][j] = (i!=j?INF:0);
- w(m){
- cin>>u>>v>>w;
- dist[0][u][v]=w, dist[0][v][u]=w;
- }
- fw();
- cin>>p;
- w(p){
- cin>>u>>v>>w;
- cout<<((dist[w][u][v]!=INF)?dist[w][u][v]:-1)<<'\n';
- }
- }
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement