Language: C

/*

?????????????????? ????????\?????????????¬???¨???

??? ???
???????????´??????????´\????????????????????????????????§????????????????¨??????????????????????????????????
????????????????????§??????????????????????????????????????????????????§????????????????????????????????????
??????????????\??????????????????????????¨?????\???????????????????????????????????????????????????????????°
??????????¨????????????????????????????????????????????´?????????????????????§??????????????????????????????
?¨??????????????????????????????°??????????????£????????????????????????

??????????????±????§??????°?????\?????¨?????????????????????????????????????????????????????????????°???????
???????????????????????°????????????????????????????????????????§???? 1 ??\??? 1000 ??\????????´??°??§
??¨??????????§??????° m ??? 1 ??\??? 1000 ??\?????§????????????????????±??????????????????????????????
????§???? a b ???????§?????????? time ????????? cost ??§??¨????????? time cost ??????????????? 
1 ??\??? 1000 ??\?????¨????????????????????????????????????????§? p ?????°????§? q ???????¨???? r 
??§??¨????????? r ??? 0 ?????¨???????????????????????? 1 ?????????????°???????????????????????????????
?????????????????° k ??? 1 ??\??? 1000 ??\?????§??????????????????????????????????????????????????????
???????????¨????????????

??\ ???
?????°???????????????????????????????????\?????¨?????????????????????????????\??????????????????????????????
???????????§????????????????????????????????????????????\????????¨????????§??????
1 ?????? ??????????????±?????° n????§??????° m ?????´??° ??´??°???????§???????????????????
2 ?????? ?¬¬ 1 ?????????????????± a b cost time?????´??° ??´??° ??´??° ??´??°???????§???????????????????
3 ?????? ?¬¬ 2 ?????????????????±
???
n+1 ?????? ?¬¬ n ?????????????????±
n+2 ?????? ????????????????????° k?????´??°???
n+3 ?????? ?¬¬ 1 ?????????????????? p q r ?????´??° ??´??° ??´??°???????§???????????????????
n+4 ?????? ?¬¬ 2 ??????????????????
 ???
n+2+k ??? ?¬¬ k ??????????????????


??? ???
??\??????????????????????????¨??????????????????????????????????°????????????????????????????

*/

/*
	???????????????????????????????????????????????????????????¨???????§£???
	http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=552375#1
 */

#include <stdio.h>
 
#define MAX_STATION (100+2)
#define INF 1000000000
#define min(x, y) ((x) < (y) ? (x) : (y))
 
int croute[ MAX_STATION ][ MAX_STATION ];
int troute[ MAX_STATION ][ MAX_STATION ];
int cost[ MAX_STATION ];
int check[ MAX_STATION ];
int used[ MAX_STATION ];
int n, m;

void dijkstra(int start, int route[ MAX_STATION ][ MAX_STATION ] )
{
	int x, y, min;
	
	for( x = 0 ; x < n ; x++ ) {
		cost[ x ] = INF;
		used[ x ] = 0;
	}
	
	cost[ start ] = 0;
	
	while( 1 ) {
		min = INF;
		for ( x = 0 ; x < n ; x++ ) {
			if ( ( used[ x ] == 0 ) && ( min > cost[ x ] ) ) {
				min = cost[ x ];
			}
		}
		if ( min == INF ) {
			break;
		}
		
		for ( y = 0 ; y < n ; y++ ) {
			if ( cost[ y ] == min ) {
				for ( x = 0 ; x < n ; x++ ) {
					if ( cost[ x ] > route[ x ][ y ] + cost[ y ] ) {
						cost[ x ] = route[ x ][ y ] + cost[ y ];
					}
				}
			}
		}
	}
}
 
int main( void )
{
	int i, j, k;
	int result;

	while ( scanf( "%d %d", &n, &m ), n != 0 ) {
		for ( i = 0 ; i < MAX_STATION ; i++ ) {
			for (j = 0 ; j < MAX_STATION ; j++ ) {
				croute[ i ][ j ] = ( i == j ) ? 0 : MAX;
				troute[ i ][ j ] = ( i == j ) ? 0 : MAX;
			}
		}
		while (n > 0) {
			int a, b, c, t;
			scanf( "%d %d %d %d", &a, &b, &c, &t );
			croute[ a ][ b ] = croute[ b ][ a ] = c;
			troute[ a ][ b ] = troute[ b ][ a ] = t;
			n--;
		}
		
		scanf( "%d", &k );
		while ( k > 0 ) {
			int p, q, r;
			scanf( "%d %d %d", &p, &q, &r );
			dijkstra( p, ( r == 0 ) ? croute : troute );
			result = cost[ q ];
			printf( "%d\n", result );
			k--;
		}
	}
	return 0;
}

Compiler output:
main.c: In function 'main':
main.c:101:69: error: 'MAX' undeclared (first use in this function)
  101 |                                 croute[ i ][ j ] = ( i == j ) ? 0 : MAX;
      |                                                                     ^~~
main.c:101:69: note: each undeclared identifier is reported only once for each function it appears in