stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <queue>

#include <functional>

#include <cstring>

using namespace std;

#define MAX_V 10240

 

// 从?点from指向?点to的???cost的?

typedef struct edge

{

	int to, distance, cost;

	edge(){}

	edge(int to, int distance, int cost) : to(to), distance(distance), cost(cost){}

	bool operator > (const edge & b) const

	{

		return distance != b.distance  ? distance > b.distance : cost > b.cost;

	}

} P;

 

// first 最短路径，second?点?号

 

// ?

vector<edge> G[MAX_V];

 

// V是?点数

int V;

bool visited[MAX_V];

 

// 求解从?点s出?到所有点的最短花?

int dijkstra(int s)

{

	int result = 0;

	priority_queue<P, vector<P>, greater<P> > que;

	memset(visited, 0, V * sizeof(bool));

	que.push(P(0, 0, 0));

 

	while (!que.empty())

	{

		P p = que.top(); que.pop();

		int v = p.to;

		if (visited[v]) continue;

		visited[v] = true;

		result += p.cost;

		for (int i = 0; i < G[v].size(); ++i)

		{

			edge e = G[v][i];

			que.push(P(G[v][i].to, p.distance + G[v][i].distance, G[v][i].cost));

		}

	}

 

	return result;

}

 

///////////////////////////SubMain//////////////////////////////////

int main(int argc, char *argv[])

{

	int /*N = V,*/ M;

	while (cin >> V >> M && V)

	{

		for (int i = 0; i < V; ++i)

		{

			G[i].clear();

		}

		for (int i = 0; i < M; ++i)

		{

			int u, v, d, c;

			cin >> u >> v >> d >> c;

			--u, --v;

			G[u].push_back(edge(v, d, c));

			G[v].push_back(edge(u, d, c));

		}

 

		cout << dijkstra(0) << endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.0394003779094017x):
#include <cstdio>

#include <cstring>

#include <algorithm>



using namespace std;



const int inf = 0x3f3f3f3f;

const int N = 10414;

const int M = 40414;



struct Edge{

	int u, v, d, c;

	int next;

}edge[M];



int cnt, head[N];

int vis[N], dis[N], cost[N];

int op, tp, link[18014];



void add_edge(int u, int v, int d, int c);

void spfa(int n);



int main(){

	int n, m, i, u, v, d, c;

	while(~scanf("%d %d", &n, &m) && (n || m)){

		cnt = 0;

		memset(head, -1, sizeof(head));

		for(i = 0; i < m; i++){

			scanf("%d %d %d %d", &u, &v, &d, &c);

			add_edge(u, v, d, c);

			add_edge(v, u, d, c);

		}

		spfa(n);

	}

	return 0;

}

void add_edge(int u, int v, int d, int c){

	edge[cnt].u = u;

	edge[cnt].v = v;

	edge[cnt].d = d;

	edge[cnt].c = c;

	edge[cnt].next = head[u];

	head[u] = cnt++;

	return;

}

void spfa(int n){

	int i, u, v, d, c, sum;

	memset(vis, 0, sizeof(vis));

	memset(dis, inf, sizeof(dis));

	memset(cost, inf, sizeof(cost));

	op = tp = 0;

	vis[1] = 1, dis[1] = 0, cost[1] = 0;

	link[tp++] = 1;

	while(op < tp){

		u = link[op++];

		vis[u] = 0;

		for(i = head[u]; ~i; i = edge[i].next){

			v = edge[i].v, d = edge[i].d, c = edge[i].c;



			if(dis[v] > dis[u] + d || (dis[v] == dis[u] + d && cost[v] > c)){

				dis[v] = dis[u] + d;

				cost[v] = c;

				if(!vis[v]){

					vis[v] = 1;

					link[tp++] = v;

				}

			}

		}

	}

	sum = 0;

	for(i = 1; i <= n; i++){

		sum += cost[i];

	}

	printf("%d\n", sum);

	return;

}
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<queue>

#include<algorithm>

#include<cstring>

using namespace std;

const int maxn  = 1e4+10;

const int INF = 0x3f3f3f3f;

typedef pair<int,int> P;

struct edge{

	int to,dis,cost;

		

};



int d[maxn];

int value[maxn];



int N,M;



int dijkstra(vector<edge>G[])

{



	memset(d,INF,sizeof(d));

	//memset(value,INF,sizeof(value));

	priority_queue<P,vector<P>,greater<P> > que;

		

	d[1] = 0;

	value[1] = 0;

	que.push(P(d[1],1));

	

	int res = 0;

	while(!que.empty())

	{

		P p  = que.top(); que.pop();

		

		int v = p.second;

		if(d[v] < p.first)

			continue;

			

		res += value[v];

		

		for(int i = 0; i < G[v].size(); i++)

		{

			edge e = G[v][i];

			if(d[e.to] == d[v] + e.dis)

				value[e.to] = min(value[e.to],e.cost);

			if(d[e.to] > d[v] + e.dis)

			{

				d[e.to] = d[v] + e.dis;

				que.push(P(d[e.to],e.to));

				

				value[e.to] = e.cost;

			}

		}

	}

	return res;

	

}



int main()

{



	//freopen("c:\\users\\administrator\\desktop\\in.txt","r",stdin);

	while(cin >> N >> M, N||M)

	{

		

		vector<edge> G[maxn];

		for(int i =0; i < M; i++)

		{

			int u,v,d,c;

			edge e;

			cin >> u >> v >> d >> c;

			e.to= v, e.dis= d, e.cost =c;

			G[u].push_back(e);

			e.to= u;

			G[v].push_back(e);	

		}

		

		int res = dijkstra(G);

		cout << res <<endl;

	}		

} 

// Faster C++ solution for the same problem (measured speedup: 3.4026947643034435x):
#include <cstdio>

#include <cstring>

#include <algorithm>



using namespace std;



const int inf = 0x3f3f3f3f;

const int N = 10414;

const int M = 40414;



struct Edge{

	int u, v, d, c;

	int next;

}edge[M];



int cnt, head[N];

int vis[N], dis[N], cost[N];

int op, tp, link[18014];



void add_edge(int u, int v, int d, int c);

void spfa(int n);



int main(){

	int n, m, i, u, v, d, c;

	while(~scanf("%d %d", &n, &m) && (n || m)){

		cnt = 0;

		memset(head, -1, sizeof(head));

		for(i = 0; i < m; i++){

			scanf("%d %d %d %d", &u, &v, &d, &c);

			add_edge(u, v, d, c);

			add_edge(v, u, d, c);

		}

		spfa(n);

	}

	return 0;

}

void add_edge(int u, int v, int d, int c){

	edge[cnt].u = u;

	edge[cnt].v = v;

	edge[cnt].d = d;

	edge[cnt].c = c;

	edge[cnt].next = head[u];

	head[u] = cnt++;

	return;

}

void spfa(int n){

	int i, u, v, d, c, sum;

	memset(vis, 0, sizeof(vis));

	memset(dis, inf, sizeof(dis));

	memset(cost, inf, sizeof(cost));

	op = tp = 0;

	vis[1] = 1, dis[1] = 0, cost[1] = 0;

	link[tp++] = 1;

	while(op < tp){

		u = link[op++];

		vis[u] = 0;

		for(i = head[u]; ~i; i = edge[i].next){

			v = edge[i].v, d = edge[i].d, c = edge[i].c;



			if(dis[v] > dis[u] + d || (dis[v] == dis[u] + d && cost[v] > c)){

				dis[v] = dis[u] + d;

				cost[v] = c;

				if(!vis[v]){

					vis[v] = 1;

					link[tp++] = v;

				}

			}

		}

	}

	sum = 0;

	for(i = 1; i <= n; i++){

		sum += cost[i];

	}

	printf("%d\n", sum);

	return;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

struct node{

    int next,d,c;

};

const int maxn=10005;

int n,m;

int d[maxn],c[maxn];

bool vis[maxn];

void init()

{

    for(int i=0;i<maxn;i++)

        d[i]=c[i]=1e9,vis[i]=0;

}

int main()

{

    while(~scanf("%d%d",&n,&m))

    {

        if(n==0&&m==0) return 0;

        init();vector<node> v[maxn];

        for(int i=0;i<m;i++)

        {

            int x,y,d,c;

            scanf("%d%d%d%d",&x,&y,&d,&c);

            v[x].push_back(node{y,d,c});

            v[y].push_back(node{x,d,c});

        }

        queue<int> q;

        q.push(1);

        d[1]=c[1]=0;vis[1]=1;

        while(!q.empty())

        {

            int u=q.front();q.pop();vis[u]=0;

            for(int i=0;i<v[u].size();i++)

            {

                int nx=v[u][i].next;

                if(d[nx]==d[u]+v[u][i].d&&c[nx]>v[u][i].c){

                        c[nx]=v[u][i].c;

                }

                if(d[nx]>d[u]+v[u][i].d)

                {

                    d[nx]=d[u]+v[u][i].d;

                    c[nx]=v[u][i].c;

                    if(vis[nx]) continue;

                    vis[nx]=1;

                    q.push(nx);

                }

            }

        }

        int ans=0;

        for(int i=2;i<=n;i++) ans+=c[i];

        cout<<ans<<endl;

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.541942470930928x):
#include <cstdio>

#include <cstring>

#include <algorithm>



using namespace std;



const int inf = 0x3f3f3f3f;

const int N = 10414;

const int M = 40414;



struct Edge{

	int u, v, d, c;

	int next;

}edge[M];



int cnt, head[N];

int vis[N], dis[N], cost[N];

int op, tp, link[18014];



void add_edge(int u, int v, int d, int c);

void spfa(int n);



int main(){

	int n, m, i, u, v, d, c;

	while(~scanf("%d %d", &n, &m) && (n || m)){

		cnt = 0;

		memset(head, -1, sizeof(head));

		for(i = 0; i < m; i++){

			scanf("%d %d %d %d", &u, &v, &d, &c);

			add_edge(u, v, d, c);

			add_edge(v, u, d, c);

		}

		spfa(n);

	}

	return 0;

}

void add_edge(int u, int v, int d, int c){

	edge[cnt].u = u;

	edge[cnt].v = v;

	edge[cnt].d = d;

	edge[cnt].c = c;

	edge[cnt].next = head[u];

	head[u] = cnt++;

	return;

}

void spfa(int n){

	int i, u, v, d, c, sum;

	memset(vis, 0, sizeof(vis));

	memset(dis, inf, sizeof(dis));

	memset(cost, inf, sizeof(cost));

	op = tp = 0;

	vis[1] = 1, dis[1] = 0, cost[1] = 0;

	link[tp++] = 1;

	while(op < tp){

		u = link[op++];

		vis[u] = 0;

		for(i = head[u]; ~i; i = edge[i].next){

			v = edge[i].v, d = edge[i].d, c = edge[i].c;



			if(dis[v] > dis[u] + d || (dis[v] == dis[u] + d && cost[v] > c)){

				dis[v] = dis[u] + d;

				cost[v] = c;

				if(!vis[v]){

					vis[v] = 1;

					link[tp++] = v;

				}

			}

		}

	}

	sum = 0;

	for(i = 1; i <= n; i++){

		sum += cost[i];

	}

	printf("%d\n", sum);

	return;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

const int N = 1E4 + 7;

bool vis[N];

int n, m;

typedef struct node

{

   int to,dis,cost;

   node(){}

   node(int a,int b,int c) : to(a),dis(b),cost(c) {}

   bool operator < (const node &a) const {

       return dis == a.dis ? cost > a.cost : dis > a.dis;

   }

}P;

vector<P>g[N];

int dij()

{

    int ans = 0;

    priority_queue<P> pq;

    pq.push(P(1,0,0));

    while(!pq.empty()) {

        P now = pq.top() ; pq.pop();

        if(vis[now.to]) continue;

        vis[now.to] = true;

        ans += now.cost;

        for(int i = 0;i < g[now.to].size();i ++) {

            P temp = g[now.to][i];

            pq.push(P(temp.to, now.dis + temp.dis, temp.cost));

        }

    }

    return ans;

}

int main()

{

   // freopen("f:\\jj.txt","r",stdin);

    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

    while(cin >> n >> m) {

        if(n + m == 0)  break;

        for(int i = 1;i <= n;i ++)  g[i].clear();

        memset(vis, 0, sizeof(vis));

        for(int i = 1;i <= m;i ++) {

            int a,b,c,d;

            cin >> a >> b >> c >> d;

            g[a].push_back(P(b,c,d));

            g[b].push_back(P(a,c,d));

        }

        cout << dij() << endl;

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.0388247630364726x):
#include <cstdio>

#include <cstring>

#include <algorithm>



using namespace std;



const int inf = 0x3f3f3f3f;

const int N = 10414;

const int M = 40414;



struct Edge{

	int u, v, d, c;

	int next;

}edge[M];



int cnt, head[N];

int vis[N], dis[N], cost[N];

int op, tp, link[18014];



void add_edge(int u, int v, int d, int c);

void spfa(int n);



int main(){

	int n, m, i, u, v, d, c;

	while(~scanf("%d %d", &n, &m) && (n || m)){

		cnt = 0;

		memset(head, -1, sizeof(head));

		for(i = 0; i < m; i++){

			scanf("%d %d %d %d", &u, &v, &d, &c);

			add_edge(u, v, d, c);

			add_edge(v, u, d, c);

		}

		spfa(n);

	}

	return 0;

}

void add_edge(int u, int v, int d, int c){

	edge[cnt].u = u;

	edge[cnt].v = v;

	edge[cnt].d = d;

	edge[cnt].c = c;

	edge[cnt].next = head[u];

	head[u] = cnt++;

	return;

}

void spfa(int n){

	int i, u, v, d, c, sum;

	memset(vis, 0, sizeof(vis));

	memset(dis, inf, sizeof(dis));

	memset(cost, inf, sizeof(cost));

	op = tp = 0;

	vis[1] = 1, dis[1] = 0, cost[1] = 0;

	link[tp++] = 1;

	while(op < tp){

		u = link[op++];

		vis[u] = 0;

		for(i = head[u]; ~i; i = edge[i].next){

			v = edge[i].v, d = edge[i].d, c = edge[i].c;



			if(dis[v] > dis[u] + d || (dis[v] == dis[u] + d && cost[v] > c)){

				dis[v] = dis[u] + d;

				cost[v] = c;

				if(!vis[v]){

					vis[v] = 1;

					link[tp++] = v;

				}

			}

		}

	}

	sum = 0;

	for(i = 1; i <= n; i++){

		sum += cost[i];

	}

	printf("%d\n", sum);

	return;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<string>

#include<cstring>

#include<algorithm>

#include<queue>

#include<vector>

#define N 20100

#define M 50010

#define rg register

using namespace std;

typedef long long ll;

typedef double db;

int n,m,tot=0;

int dis[N],head[N],vis[N];

int nxt[M],to[M],w[M],c[M];

void link(int x,int y,int z,int v){

	nxt[tot]=head[x],to[tot]=y,w[tot]=z,c[tot]=v,head[x]=tot++;

}

void spfa(){

	queue <int> q;

	memset(dis,0x3f,sizeof(dis));

	memset(vis,0,sizeof(vis));

	q.push(1),dis[1]=0,vis[1]=1;

	while (!q.empty()){

		int x=q.front();q.pop();

		for (int i=head[x];i!=-1;i=nxt[i]){

			int v=to[i];

			if (dis[v]<=dis[x]+w[i]) continue;

			dis[v]=dis[x]+w[i];

			if (!vis[v]) vis[v]=1,q.push(v);

		}

		vis[x]=0;

	}

}

int main(){

//	freopen ("2249.in","r",stdin);

//	freopen ("2249.out","w",stdout);

	while (scanf ("%d%d",&n,&m)&&(n||m)){

		memset(head,-1,sizeof(head));

		tot=0;int x,y,z,v;

		for (int i=1;i<=m;++i){

			scanf ("%d%d%d%d",&x,&y,&z,&v);

			link(x,y,z,v),link(y,x,z,v);

		}

		spfa();

		int ans=0;

		for (int i=2;i<=n;++i){

			int mx=2000;

			for (int j=head[i];j!=-1;j=nxt[j]){

				v=to[j];

				if (dis[i]==dis[v]+w[j]) mx=min(mx,c[j]);

			}

			ans+=mx;

		}

		printf ("%d\n",ans);

	

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.115394566194256x):
#include <cstdio>

#include <cstring>

#include <algorithm>



using namespace std;



const int inf = 0x3f3f3f3f;

const int N = 10414;

const int M = 40414;



struct Edge{

	int u, v, d, c;

	int next;

}edge[M];



int cnt, head[N];

int vis[N], dis[N], cost[N];

int op, tp, link[18014];



void add_edge(int u, int v, int d, int c);

void spfa(int n);



int main(){

	int n, m, i, u, v, d, c;

	while(~scanf("%d %d", &n, &m) && (n || m)){

		cnt = 0;

		memset(head, -1, sizeof(head));

		for(i = 0; i < m; i++){

			scanf("%d %d %d %d", &u, &v, &d, &c);

			add_edge(u, v, d, c);

			add_edge(v, u, d, c);

		}

		spfa(n);

	}

	return 0;

}

void add_edge(int u, int v, int d, int c){

	edge[cnt].u = u;

	edge[cnt].v = v;

	edge[cnt].d = d;

	edge[cnt].c = c;

	edge[cnt].next = head[u];

	head[u] = cnt++;

	return;

}

void spfa(int n){

	int i, u, v, d, c, sum;

	memset(vis, 0, sizeof(vis));

	memset(dis, inf, sizeof(dis));

	memset(cost, inf, sizeof(cost));

	op = tp = 0;

	vis[1] = 1, dis[1] = 0, cost[1] = 0;

	link[tp++] = 1;

	while(op < tp){

		u = link[op++];

		vis[u] = 0;

		for(i = head[u]; ~i; i = edge[i].next){

			v = edge[i].v, d = edge[i].d, c = edge[i].c;



			if(dis[v] > dis[u] + d || (dis[v] == dis[u] + d && cost[v] > c)){

				dis[v] = dis[u] + d;

				cost[v] = c;

				if(!vis[v]){

					vis[v] = 1;

					link[tp++] = v;

				}

			}

		}

	}

	sum = 0;

	for(i = 1; i <= n; i++){

		sum += cost[i];

	}

	printf("%d\n", sum);

	return;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define db double

#define ll long long

#define RG register



inline int gi()

{

	RG int ret; RG bool flag; RG char ch;

	ret=0, flag=true, ch=getchar();

	while (ch < '0' || ch > '9')

		ch == '-' ? flag=false : 0, ch=getchar();

	while (ch >= '0' && ch <= '9')

		ret=(ret<<3)+(ret<<1)+ch-'0', ch=getchar();

	return flag ? ret : -ret;

}



const db pi = acos(-1.0);

const int N = 142857, inf = 1<<30;



int f[N],et[N],ed[N],nx[N],ew[N],dis[N],cst[N];

bool vis[N];

queue <int> q;

int num;



inline void add(int x,int y,int z,int w)

{

	et[++num]=y, nx[num]=f[x], ed[num]=z, ew[num]=w, f[x]=num;

}



int main()

{

	int n,m,i,x,y,z,w;

	while (true)

		{

			n=gi(), m=gi();

			if (n == 0)

				break;

			for (i=1; i<=m; ++i)

				{

					x=gi(), y=gi(), z=gi(), w=gi();

					add(x,y,z,w), add(y,x,z,w);

				}

			for (i=2; i<=n; ++i)

				cst[i]=dis[i]=inf;

			q.push(1), vis[1]=true;

			while (!q.empty())

				{

					x=q.front(), q.pop(), vis[x]=false;

					for (i=f[x]; i; i=nx[i])

						{

							y=et[i], z=ed[i], w=ew[i];

							if (dis[y] > dis[x]+z)

								{

									dis[y]=dis[x]+z;

									cst[y]=cst[x]+w;

									if (!vis[y])

										q.push(y), vis[y]=true;

								}

							if (dis[y] == dis[x]+z && cst[y] > w)

								cst[y]=w;

						}

				}

			x=0;

			for (i=2; i<=n; ++i)

				x+=cst[i];

			printf("%d\n",x);

			for (i=1; i<=n; ++i)

				f[i]=0;

			num=0;

		}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.330675825129881x):
#include <cstdio>

#include <cstring>

#include <algorithm>



using namespace std;



const int inf = 0x3f3f3f3f;

const int N = 10414;

const int M = 40414;



struct Edge{

	int u, v, d, c;

	int next;

}edge[M];



int cnt, head[N];

int vis[N], dis[N], cost[N];

int op, tp, link[18014];



void add_edge(int u, int v, int d, int c);

void spfa(int n);



int main(){

	int n, m, i, u, v, d, c;

	while(~scanf("%d %d", &n, &m) && (n || m)){

		cnt = 0;

		memset(head, -1, sizeof(head));

		for(i = 0; i < m; i++){

			scanf("%d %d %d %d", &u, &v, &d, &c);

			add_edge(u, v, d, c);

			add_edge(v, u, d, c);

		}

		spfa(n);

	}

	return 0;

}

void add_edge(int u, int v, int d, int c){

	edge[cnt].u = u;

	edge[cnt].v = v;

	edge[cnt].d = d;

	edge[cnt].c = c;

	edge[cnt].next = head[u];

	head[u] = cnt++;

	return;

}

void spfa(int n){

	int i, u, v, d, c, sum;

	memset(vis, 0, sizeof(vis));

	memset(dis, inf, sizeof(dis));

	memset(cost, inf, sizeof(cost));

	op = tp = 0;

	vis[1] = 1, dis[1] = 0, cost[1] = 0;

	link[tp++] = 1;

	while(op < tp){

		u = link[op++];

		vis[u] = 0;

		for(i = head[u]; ~i; i = edge[i].next){

			v = edge[i].v, d = edge[i].d, c = edge[i].c;



			if(dis[v] > dis[u] + d || (dis[v] == dis[u] + d && cost[v] > c)){

				dis[v] = dis[u] + d;

				cost[v] = c;

				if(!vis[v]){

					vis[v] = 1;

					link[tp++] = v;

				}

			}

		}

	}

	sum = 0;

	for(i = 1; i <= n; i++){

		sum += cost[i];

	}

	printf("%d\n", sum);

	return;

}
// Slower C++ solution:
#include<iostream>

#include<cstdlib>

#include<cstdio>

#include<cmath>

#include<algorithm>

#include<cstring>

#include<queue>

#include<vector>

#include<stack>

#define ls k<<1

#define rs k<<1|1

#define RG register

#define MAXN 50010

#define LL long long int

using namespace std;

const int INF=0x7fffffff;

struct node{

	int next;

	int to;

	int w;

	int c;

}t[MAXN];

int head[MAXN];

int num;

int dis[MAXN],vis[MAXN],cost[MAXN];

int n,m;

void add(int from,int to,int w,int c)

{

	t[++num].next=head[from];

	t[num].to=to;

	t[num].w=w;

	t[num].c=c;

	head[from]=num;

}

void spfa()

{

	for(int i=1;i<=n;i++)

		{

			dis[i]=INF;vis[i]=0;cost[i]=INF;

		}

	cost[1]=dis[1]=0;vis[1]=1;

	queue<int>q;q.push(1);

	while(!q.empty())

		{

			int u=q.front();q.pop();vis[u]=0;

			for(int i=head[u];i;i=t[i].next)

				{

					int v=t[i].to;

					if(dis[v]>dis[u]+t[i].w||(dis[v]==dis[u]+t[i].w&&cost[v]>t[i].c))

						{

							dis[v]=dis[u]+t[i].w;

							cost[v]=t[i].c;

							if(!vis[v])

								{

									vis[v]=1;q.push(v);

								}

						}

				}

		}

}

int main()

{

//	freopen("1.in","r" ,stdin);

	//freopen("1.out","w",stdout);

	while(1)

		{

			scanf("%d%d",&n,&m);if(n==0&&m==0) break;

			int x,y,z,k;

			memset(head,0,sizeof(head));num=0;

			for(int i=1;i<=m;i++)

				{

					scanf("%d%d%d%d",&x,&y,&z,&k);

					add(x,y,z,k);add(y,x,z,k);

				}

			spfa();

			int ans=0;

			for(int i=1;i<=n;i++) ans+=cost[i];

			cout<<ans<<endl;

		}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.016318382722789x):
#include <cstdio>

#include <cstring>

#include <algorithm>



using namespace std;



const int inf = 0x3f3f3f3f;

const int N = 10414;

const int M = 40414;



struct Edge{

	int u, v, d, c;

	int next;

}edge[M];



int cnt, head[N];

int vis[N], dis[N], cost[N];

int op, tp, link[18014];



void add_edge(int u, int v, int d, int c);

void spfa(int n);



int main(){

	int n, m, i, u, v, d, c;

	while(~scanf("%d %d", &n, &m) && (n || m)){

		cnt = 0;

		memset(head, -1, sizeof(head));

		for(i = 0; i < m; i++){

			scanf("%d %d %d %d", &u, &v, &d, &c);

			add_edge(u, v, d, c);

			add_edge(v, u, d, c);

		}

		spfa(n);

	}

	return 0;

}

void add_edge(int u, int v, int d, int c){

	edge[cnt].u = u;

	edge[cnt].v = v;

	edge[cnt].d = d;

	edge[cnt].c = c;

	edge[cnt].next = head[u];

	head[u] = cnt++;

	return;

}

void spfa(int n){

	int i, u, v, d, c, sum;

	memset(vis, 0, sizeof(vis));

	memset(dis, inf, sizeof(dis));

	memset(cost, inf, sizeof(cost));

	op = tp = 0;

	vis[1] = 1, dis[1] = 0, cost[1] = 0;

	link[tp++] = 1;

	while(op < tp){

		u = link[op++];

		vis[u] = 0;

		for(i = head[u]; ~i; i = edge[i].next){

			v = edge[i].v, d = edge[i].d, c = edge[i].c;



			if(dis[v] > dis[u] + d || (dis[v] == dis[u] + d && cost[v] > c)){

				dis[v] = dis[u] + d;

				cost[v] = c;

				if(!vis[v]){

					vis[v] = 1;

					link[tp++] = v;

				}

			}

		}

	}

	sum = 0;

	for(i = 1; i <= n; i++){

		sum += cost[i];

	}

	printf("%d\n", sum);

	return;

}
// Slower C++ solution:
#include <cstdio>

#include <queue>

#include <vector>

#include <algorithm>



using namespace std;

const int INF = 0x3f3f3f3f;



const int maxn = 10240;



struct edge {

	int to, dis, cost;

	edge(int t, int d, int c) : to(t), dis(d), cost(c) {}

};





typedef pair<int, int> p;

priority_queue<p, vector<p>, greater<p> > q;

vector<edge> g[maxn];



int N, M;



void read_in() {

	//scanf("%d%d", &N, &M);

	for(int i = 1; i <= N; i++)

		g[i].clear();



	int from, to, dis, cost;

	for(int i = 1; i <= M; i++) {

		scanf("%d%d%d%d", &from, &to, &dis, &cost);

		g[from].push_back(edge(to, dis, cost));

		g[to].push_back(edge(from, dis, cost));

	}

}



int solve() {

	q.push(p(0, 1));



	const int INF = 0x7777777;

	int d[maxn];



	for(int i = 2; i <= N; i++) 

		d[i] = INF;

	d[1] = 0;



	while( !q.empty() ) {

		p t = q.top();

		q.pop();



		int to = t.second, dis = t.first;

        if(d[to] < dis) continue;

		for(unsigned int i = 0; i < g[to].size(); i++) {

			edge To = g[to][i];

			if(d[To.to] > d[to] + To.dis)

				d[To.to] = d[to] + To.dis,

				q.push(p(d[To.to], To.to));

		}

	}

	//show(d);

    int ans = 0;



    for(int i = 2; i <= N; i++) {

        int tmp = INF;



        for(int j = 0; j < g[i].size(); j++) {

            edge e = g[i][j];

            if(d[e.to] + e.dis == d[i] and e.cost < tmp)

                tmp = e.cost;

        }

        ans += tmp;

    }



    return ans;

}



int main() {

	while(scanf("%d %d", &N, &M) and N) {

		read_in();

		printf("%d\n", solve());

	}

	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 2.8094850059244534x):
#include <cstdio>

#include <cstring>

#include <algorithm>



using namespace std;



const int inf = 0x3f3f3f3f;

const int N = 10414;

const int M = 40414;



struct Edge{

	int u, v, d, c;

	int next;

}edge[M];



int cnt, head[N];

int vis[N], dis[N], cost[N];

int op, tp, link[18014];



void add_edge(int u, int v, int d, int c);

void spfa(int n);



int main(){

	int n, m, i, u, v, d, c;

	while(~scanf("%d %d", &n, &m) && (n || m)){

		cnt = 0;

		memset(head, -1, sizeof(head));

		for(i = 0; i < m; i++){

			scanf("%d %d %d %d", &u, &v, &d, &c);

			add_edge(u, v, d, c);

			add_edge(v, u, d, c);

		}

		spfa(n);

	}

	return 0;

}

void add_edge(int u, int v, int d, int c){

	edge[cnt].u = u;

	edge[cnt].v = v;

	edge[cnt].d = d;

	edge[cnt].c = c;

	edge[cnt].next = head[u];

	head[u] = cnt++;

	return;

}

void spfa(int n){

	int i, u, v, d, c, sum;

	memset(vis, 0, sizeof(vis));

	memset(dis, inf, sizeof(dis));

	memset(cost, inf, sizeof(cost));

	op = tp = 0;

	vis[1] = 1, dis[1] = 0, cost[1] = 0;

	link[tp++] = 1;

	while(op < tp){

		u = link[op++];

		vis[u] = 0;

		for(i = head[u]; ~i; i = edge[i].next){

			v = edge[i].v, d = edge[i].d, c = edge[i].c;



			if(dis[v] > dis[u] + d || (dis[v] == dis[u] + d && cost[v] > c)){

				dis[v] = dis[u] + d;

				cost[v] = c;

				if(!vis[v]){

					vis[v] = 1;

					link[tp++] = v;

				}

			}

		}

	}

	sum = 0;

	for(i = 1; i <= n; i++){

		sum += cost[i];

	}

	printf("%d\n", sum);

	return;

}