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

#include <vector>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <iostream>

#include <algorithm>

const int INF=0x3f3f3f3f;

using namespace std;

struct edge{

    int to,cost,w;

};

int V,d[10005],dis[10005];

vector<edge> G[20005];

typedef pair<int,int> P;

void dijkstra(int s){

    int i,v;

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

	fill(d,d+V+1,INF);

	fill(dis,dis+V+1,INF);

	d[s]=dis[s]=0;

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

	while(!que.empty()){

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

		v=p.second;

		if(d[v]<p.first)

        continue;

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

			edge e=G[v][i];

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

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

                dis[e.to]=e.w;

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

			}

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

            dis[e.to]=min(dis[e.to],e.w);

		}

	}

}

int main(){

    int m,st,en,i,j,x,y,z,q,ans;

    edge temp;

    while(scanf("%d%d",&V,&m)!=EOF&&(V||m)){

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

        G[i].clear();

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

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

            temp.to=y;temp.cost=z;temp.w=q;

            G[x].push_back(temp);

            temp.to=x;

            G[y].push_back(temp);

        }

        dijkstra(1);

        ans=0;

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

        ans+=dis[i];

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

    }

    return 0;

}

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

#include<queue>

#include<functional>

#include<cstring>



using namespace std;



#define maxn 10240 

#define INF 0x3f3f3f3f;



typedef struct edge{

	int to,dis,cos;

	edge(){}

	edge(int to,int dis,int cos):to(to),dis(dis),cos(cos){}

};

typedef pair<int ,int> P;



vector<edge>G[maxn];



int d[maxn];

int v;//定点



void dijkstra(int s){

	priority_queue<P,vector<P>,greater<P> > que;//优先输出小数据；

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

	d[s]=0;

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

	while(!que.empty())

	{

		P p=que.top();

		que.pop();

		int v=p.second;

		if(d[v]<p.first)continue;

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

		{

			edge e=G[v][i];

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

			{

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

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

			}

		}

	}	

} 

int main()

{

	int m;

	while(cin>>v>>m)

	{

		if(v==0&&m==0)break;

		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)); 

		}

		dijkstra(0);

		int ans=0;

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

		{

			int min=INF;

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

			{

				if(d[G[i][j].to]+G[i][j].dis==d[i]&&G[i][j].cos<min)

				{

					min=G[i][j].cos;

				}

				

			} 

			ans+=min;

		}cout<<ans<<endl;

	}

	return 0;

}
// 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: 1.1205635765219264x):
#include<iostream>

#include<queue>

#include<functional>

#include<cstring>



using namespace std;



#define maxn 10240 

#define INF 0x3f3f3f3f;



typedef struct edge{

	int to,dis,cos;

	edge(){}

	edge(int to,int dis,int cos):to(to),dis(dis),cos(cos){}

};

typedef pair<int ,int> P;



vector<edge>G[maxn];



int d[maxn];

int v;//定点



void dijkstra(int s){

	priority_queue<P,vector<P>,greater<P> > que;//优先输出小数据；

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

	d[s]=0;

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

	while(!que.empty())

	{

		P p=que.top();

		que.pop();

		int v=p.second;

		if(d[v]<p.first)continue;

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

		{

			edge e=G[v][i];

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

			{

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

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

			}

		}

	}	

} 

int main()

{

	int m;

	while(cin>>v>>m)

	{

		if(v==0&&m==0)break;

		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)); 

		}

		dijkstra(0);

		int ans=0;

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

		{

			int min=INF;

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

			{

				if(d[G[i][j].to]+G[i][j].dis==d[i]&&G[i][j].cos<min)

				{

					min=G[i][j].cos;

				}

				

			} 

			ans+=min;

		}cout<<ans<<endl;

	}

	return 0;

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

#include <vector>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <iostream>

#include <algorithm>

const int INF=0x3f3f3f3f;

using namespace std;

struct edge{

    int to,cost,w;

};

int V,d[10005],dis[10005];

vector<edge> G[20005];

typedef pair<int,int> P;

void dijkstra(int s){

    int i,v;

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

	fill(d,d+V+1,INF);

	fill(dis,dis+V+1,INF);

	d[s]=dis[s]=0;

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

	while(!que.empty()){

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

		v=p.second;

		if(d[v]<p.first)

        continue;

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

			edge e=G[v][i];

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

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

                dis[e.to]=e.w;

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

			}

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

            dis[e.to]=min(dis[e.to],e.w);

		}

	}

}

int main(){

    int m,st,en,i,j,x,y,z,q,ans;

    edge temp;

    while(scanf("%d%d",&V,&m)!=EOF&&(V||m)){

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

        G[i].clear();

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

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

            temp.to=y;temp.cost=z;temp.w=q;

            G[x].push_back(temp);

            temp.to=x;

            G[y].push_back(temp);

        }

        dijkstra(1);

        ans=0;

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

        ans+=dis[i];

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

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2537152952407407x):
#include<stdio.h>

#include<string.h>  

#include<math.h>  

  

//#include<map>   

//#include<set>

#include<deque>  

#include<queue>  

#include<stack>  

#include<bitset> 

#include<string>  

#include<iostream>  

#include<algorithm>  

using namespace std;  

  

#define ll long long  

#define INF 0x3f3f3f3f  

#define mod 1000000

#define clean(a,b) memset(a,b,sizeof(a))// 水印 



struct node{

	int to,next,dis,cost;

}edge[40100];

int head[10100];

int dis[10100],cost[10100];

bool vst[10100];

int n,m,k;



void spfa(int x)

{

	clean(dis,INF);

	clean(cost,INF);

	clean(vst,0);

	queue<int> q;

	dis[x]=0;

	cost[x]=0;

	q.push(x);

	while(!q.empty())

	{

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

		vst[x]=0;

		for(int i=head[x];i!=-1;i=edge[i].next)

		{

			node b=edge[i];

			if(dis[b.to]>dis[x]+b.dis)

			{

				if(!vst[b.to])

				{

					vst[b.to]=1;

					q.push(b.to);

				}

				dis[b.to]=dis[x]+b.dis;

				cost[b.to]=b.cost;

			}

			else if(dis[b.to]==dis[x]+b.dis)

			{

				if(cost[b.to]>b.cost)

					cost[b.to]=b.cost;

			}

		}

	}

}



void add(int a,int b,int dis,int cost)

{

	edge[k].to=b;

	edge[k].dis=dis;

	edge[k].cost=cost;

	edge[k].next=head[a];

	head[a]=k;

	k++;

}



int main()

{

	while(cin>>n>>m&&n!=0||m!=0)

	{

		clean(head,-1);

		k=0;

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

		{

			int a,b,d,c;

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

			add(a,b,d,c);

			add(b,a,d,c);

		}

		spfa(1);

		ll res=0;

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

			res=res+cost[i];

		cout<<res<<endl;

	}

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

using namespace std;



typedef long long ll;

const int N = 10005;

const int M = 1000000007;



int n, m;

typedef int wtype;

struct Edge { int v; wtype d, c; };

vector<Edge> e[N];

wtype dist[N], cost[N];

int pre[N];

bool vis[N];

int SPFA(int src) {

  memset(dist, 0x3f, sizeof(dist)); dist[src] = 0;

  memset(cost, 0x3f, sizeof(cost)); cost[src] = 0;

  memset(vis, 0, sizeof(vis)); vis[src] = true;

  stack<int> que; que.push(src);

  while (!que.empty()) {

    int u = que.top(); que.pop();

    vis[u] = false;

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

      int v = e[u][i].v; wtype d = e[u][i].d, c = e[u][i].c;

      if (dist[v] > dist[u] + d || (dist[v] == dist[u] + d && cost[v] != 0x3f3f3f3f && cost[v] > c)) {

        dist[v] = dist[u] + d; cost[v] = c;

        if (!vis[v]) { vis[v] = true; que.push(v); }

      }

    }

  }

  int ret = 0;

  for (int i = 1; i <= n; i++) { ret += cost[i]; }

  return ret;

}



int main() {

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

    for (int i = 1; i <= n; i++) { e[i].clear(); }

    for (int i = 0, u, v, d, c; i < m; i++) {

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

      e[u].push_back((Edge) {v, d, c});

      e[v].push_back((Edge) {u, d, c});

    }

    printf("%d\n", SPFA(1));

  }

}

// Faster C++ solution for the same problem (measured speedup: 1.147073801722088x):
#include<stdio.h>

#include<string.h>  

#include<math.h>  

  

//#include<map>   

//#include<set>

#include<deque>  

#include<queue>  

#include<stack>  

#include<bitset> 

#include<string>  

#include<iostream>  

#include<algorithm>  

using namespace std;  

  

#define ll long long  

#define INF 0x3f3f3f3f  

#define mod 1000000

#define clean(a,b) memset(a,b,sizeof(a))// 水印 



struct node{

	int to,next,dis,cost;

}edge[40100];

int head[10100];

int dis[10100],cost[10100];

bool vst[10100];

int n,m,k;



void spfa(int x)

{

	clean(dis,INF);

	clean(cost,INF);

	clean(vst,0);

	queue<int> q;

	dis[x]=0;

	cost[x]=0;

	q.push(x);

	while(!q.empty())

	{

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

		vst[x]=0;

		for(int i=head[x];i!=-1;i=edge[i].next)

		{

			node b=edge[i];

			if(dis[b.to]>dis[x]+b.dis)

			{

				if(!vst[b.to])

				{

					vst[b.to]=1;

					q.push(b.to);

				}

				dis[b.to]=dis[x]+b.dis;

				cost[b.to]=b.cost;

			}

			else if(dis[b.to]==dis[x]+b.dis)

			{

				if(cost[b.to]>b.cost)

					cost[b.to]=b.cost;

			}

		}

	}

}



void add(int a,int b,int dis,int cost)

{

	edge[k].to=b;

	edge[k].dis=dis;

	edge[k].cost=cost;

	edge[k].next=head[a];

	head[a]=k;

	k++;

}



int main()

{

	while(cin>>n>>m&&n!=0||m!=0)

	{

		clean(head,-1);

		k=0;

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

		{

			int a,b,d,c;

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

			add(a,b,d,c);

			add(b,a,d,c);

		}

		spfa(1);

		ll res=0;

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

			res=res+cost[i];

		cout<<res<<endl;

	}

}
// 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: 1.2009115701273008x):
#include<stdio.h>

#include<string.h>  

#include<math.h>  

  

//#include<map>   

//#include<set>

#include<deque>  

#include<queue>  

#include<stack>  

#include<bitset> 

#include<string>  

#include<iostream>  

#include<algorithm>  

using namespace std;  

  

#define ll long long  

#define INF 0x3f3f3f3f  

#define mod 1000000

#define clean(a,b) memset(a,b,sizeof(a))// 水印 



struct node{

	int to,next,dis,cost;

}edge[40100];

int head[10100];

int dis[10100],cost[10100];

bool vst[10100];

int n,m,k;



void spfa(int x)

{

	clean(dis,INF);

	clean(cost,INF);

	clean(vst,0);

	queue<int> q;

	dis[x]=0;

	cost[x]=0;

	q.push(x);

	while(!q.empty())

	{

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

		vst[x]=0;

		for(int i=head[x];i!=-1;i=edge[i].next)

		{

			node b=edge[i];

			if(dis[b.to]>dis[x]+b.dis)

			{

				if(!vst[b.to])

				{

					vst[b.to]=1;

					q.push(b.to);

				}

				dis[b.to]=dis[x]+b.dis;

				cost[b.to]=b.cost;

			}

			else if(dis[b.to]==dis[x]+b.dis)

			{

				if(cost[b.to]>b.cost)

					cost[b.to]=b.cost;

			}

		}

	}

}



void add(int a,int b,int dis,int cost)

{

	edge[k].to=b;

	edge[k].dis=dis;

	edge[k].cost=cost;

	edge[k].next=head[a];

	head[a]=k;

	k++;

}



int main()

{

	while(cin>>n>>m&&n!=0||m!=0)

	{

		clean(head,-1);

		k=0;

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

		{

			int a,b,d,c;

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

			add(a,b,d,c);

			add(b,a,d,c);

		}

		spfa(1);

		ll res=0;

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

			res=res+cost[i];

		cout<<res<<endl;

	}

}
// 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: 1.2500562021280706x):
#include<stdio.h>

#include<string.h>  

#include<math.h>  

  

//#include<map>   

//#include<set>

#include<deque>  

#include<queue>  

#include<stack>  

#include<bitset> 

#include<string>  

#include<iostream>  

#include<algorithm>  

using namespace std;  

  

#define ll long long  

#define INF 0x3f3f3f3f  

#define mod 1000000

#define clean(a,b) memset(a,b,sizeof(a))// 水印 



struct node{

	int to,next,dis,cost;

}edge[40100];

int head[10100];

int dis[10100],cost[10100];

bool vst[10100];

int n,m,k;



void spfa(int x)

{

	clean(dis,INF);

	clean(cost,INF);

	clean(vst,0);

	queue<int> q;

	dis[x]=0;

	cost[x]=0;

	q.push(x);

	while(!q.empty())

	{

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

		vst[x]=0;

		for(int i=head[x];i!=-1;i=edge[i].next)

		{

			node b=edge[i];

			if(dis[b.to]>dis[x]+b.dis)

			{

				if(!vst[b.to])

				{

					vst[b.to]=1;

					q.push(b.to);

				}

				dis[b.to]=dis[x]+b.dis;

				cost[b.to]=b.cost;

			}

			else if(dis[b.to]==dis[x]+b.dis)

			{

				if(cost[b.to]>b.cost)

					cost[b.to]=b.cost;

			}

		}

	}

}



void add(int a,int b,int dis,int cost)

{

	edge[k].to=b;

	edge[k].dis=dis;

	edge[k].cost=cost;

	edge[k].next=head[a];

	head[a]=k;

	k++;

}



int main()

{

	while(cin>>n>>m&&n!=0||m!=0)

	{

		clean(head,-1);

		k=0;

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

		{

			int a,b,d,c;

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

			add(a,b,d,c);

			add(b,a,d,c);

		}

		spfa(1);

		ll res=0;

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

			res=res+cost[i];

		cout<<res<<endl;

	}

}
// 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: 1.099514837270536x):
#include<stdio.h>

#include<string.h>  

#include<math.h>  

  

//#include<map>   

//#include<set>

#include<deque>  

#include<queue>  

#include<stack>  

#include<bitset> 

#include<string>  

#include<iostream>  

#include<algorithm>  

using namespace std;  

  

#define ll long long  

#define INF 0x3f3f3f3f  

#define mod 1000000

#define clean(a,b) memset(a,b,sizeof(a))// 水印 



struct node{

	int to,next,dis,cost;

}edge[40100];

int head[10100];

int dis[10100],cost[10100];

bool vst[10100];

int n,m,k;



void spfa(int x)

{

	clean(dis,INF);

	clean(cost,INF);

	clean(vst,0);

	queue<int> q;

	dis[x]=0;

	cost[x]=0;

	q.push(x);

	while(!q.empty())

	{

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

		vst[x]=0;

		for(int i=head[x];i!=-1;i=edge[i].next)

		{

			node b=edge[i];

			if(dis[b.to]>dis[x]+b.dis)

			{

				if(!vst[b.to])

				{

					vst[b.to]=1;

					q.push(b.to);

				}

				dis[b.to]=dis[x]+b.dis;

				cost[b.to]=b.cost;

			}

			else if(dis[b.to]==dis[x]+b.dis)

			{

				if(cost[b.to]>b.cost)

					cost[b.to]=b.cost;

			}

		}

	}

}



void add(int a,int b,int dis,int cost)

{

	edge[k].to=b;

	edge[k].dis=dis;

	edge[k].cost=cost;

	edge[k].next=head[a];

	head[a]=k;

	k++;

}



int main()

{

	while(cin>>n>>m&&n!=0||m!=0)

	{

		clean(head,-1);

		k=0;

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

		{

			int a,b,d,c;

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

			add(a,b,d,c);

			add(b,a,d,c);

		}

		spfa(1);

		ll res=0;

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

			res=res+cost[i];

		cout<<res<<endl;

	}

}
// Slower C++ solution:
#include "cstring"

#include "cstdio"

#include "vector"

#include "queue"

using namespace std;



const int maxn=11000;



struct edge{int to,d,c;};

edge edges[4100000];

int p;



vector<int>g[maxn];



int dis[maxn],vis[maxn],cos[maxn];

int n,m,sn;



void add(int u,int v,int d,int c)

{

	edges[++p].d=d;

	edges[p].to=v;

	edges[p].c=c;

	g[u].push_back(p);

}



int spfa(int s)

{

	memset(cos,0x3f3f3f3f,sizeof(cos));

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

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

	

	queue<int>qn;

	qn.push(s);

	dis[s]=0;

	cos[s]=0;

	vis[s]=1;

	

	while(!qn.empty())

	{

		int nn=qn.front();qn.pop();

		vis[nn]=0;

		for(int i=0,d=g[nn].size();i<d;i++)

		{

			edge &e= edges[g[nn][i]];

			if(dis[e.to]>dis[nn]+e.d || ((dis[e.to]==dis[nn]+e.d) && cos[e.to]>e.c))

			{

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

				cos[e.to]=e.c;

				

				if(!vis[e.to])

				{

					qn.push(e.to);

					vis[e.to]=1;

				}

			}

		}	

	}

	return 0;

}



int main()

{

	//freopen("q.txt","r",stdin);

	int u,v,d,c;

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

	{

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

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

			g[i].clear();

		p=0;

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

		{

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

			add(u,v,d,c);

			add(v,u,d,c);

		}

		int ans=0;

		spfa(1);

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

			ans+=cos[i];

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

	}

	return 0;

} 


// Faster C++ solution for the same problem (measured speedup: 1.1533201853603734x):
#include<stdio.h>

#include<string.h>  

#include<math.h>  

  

//#include<map>   

//#include<set>

#include<deque>  

#include<queue>  

#include<stack>  

#include<bitset> 

#include<string>  

#include<iostream>  

#include<algorithm>  

using namespace std;  

  

#define ll long long  

#define INF 0x3f3f3f3f  

#define mod 1000000

#define clean(a,b) memset(a,b,sizeof(a))// 水印 



struct node{

	int to,next,dis,cost;

}edge[40100];

int head[10100];

int dis[10100],cost[10100];

bool vst[10100];

int n,m,k;



void spfa(int x)

{

	clean(dis,INF);

	clean(cost,INF);

	clean(vst,0);

	queue<int> q;

	dis[x]=0;

	cost[x]=0;

	q.push(x);

	while(!q.empty())

	{

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

		vst[x]=0;

		for(int i=head[x];i!=-1;i=edge[i].next)

		{

			node b=edge[i];

			if(dis[b.to]>dis[x]+b.dis)

			{

				if(!vst[b.to])

				{

					vst[b.to]=1;

					q.push(b.to);

				}

				dis[b.to]=dis[x]+b.dis;

				cost[b.to]=b.cost;

			}

			else if(dis[b.to]==dis[x]+b.dis)

			{

				if(cost[b.to]>b.cost)

					cost[b.to]=b.cost;

			}

		}

	}

}



void add(int a,int b,int dis,int cost)

{

	edge[k].to=b;

	edge[k].dis=dis;

	edge[k].cost=cost;

	edge[k].next=head[a];

	head[a]=k;

	k++;

}



int main()

{

	while(cin>>n>>m&&n!=0||m!=0)

	{

		clean(head,-1);

		k=0;

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

		{

			int a,b,d,c;

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

			add(a,b,d,c);

			add(b,a,d,c);

		}

		spfa(1);

		ll res=0;

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

			res=res+cost[i];

		cout<<res<<endl;

	}

}