-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoj0200.cpp
61 lines (57 loc) · 1.32 KB
/
aoj0200.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
using namespace std;
typedef pair<int,int> P;
const int INF = ~(1<<31) / 2;
int c[100][100];
int t[100][100];
int n,m,k;
int main(){
while(1){
scanf("%d %d",&n,&m);
if(n==0) break;
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
c[i][j] = 1000000;
t[i][j] = 1000000;
}
}
for(int i=0;i<n;i++){
int a,b,co,ti;
scanf("%d %d %d %d",&a,&b,&co,&ti);
a--;b--;
c[a][b] = co;
c[b][a] = co;
t[a][b] = ti;
t[b][a] = ti;
}
for(int k=0;k<m;k++){
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
c[i][j] = min(c[i][j],c[i][k]+c[k][j]);
t[i][j] = min(t[i][j],t[i][k]+t[k][j]);
}
}
}
scanf("%d",&k);
for(int i=0;i<k;i++){
int p,q,r;
scanf("%d %d %d",&p,&q,&r);
p--;q--;
if(r)printf("%d\n",t[p][q]);
else printf("%d\n",c[p][q]);
}
}
return 0;
}