#include<bits/stdc++.h>
#define MAX 100
#define INFINITY 65535
bool marked[MAX];//标记是否合并
int pathMar[MAX][MAX];//所有路径长
int Dist[MAX];//当前连通量与其他连通量的最短距离
int main()
{
int n;//村庄数
scanf("%d", &n);
for(int i = 0; i < n; i ++)
for(int j = 0; j < n; j ++)
{
pathMar[i][j] = INFINITY;//将初始路径长度标志为最长路径长
}
int m = n * (n - 1) / 2;//输入行数
for(int i = 0; i < m; i ++)
{
int a, b, c, d;//相互连通的两个村庄,花费,是否连通
scanf("%d%d%d%d", &a, &b, &c, &d);
if(d == 1)//如果连通不用计入成本
{
pathMar[a - 1][b - 1] = pathMar[b - 1][a - 1] = 0;
}
else
{
pathMar[a - 1][b - 1] = pathMar[b - 1][a - 1] = c;
}
}
//初始化Dist
for(int i = 0; i < n; i ++)
{
Dist[i] = pathMar[0][i];
}
marked[0] =