stablegradients/pie-gem5-pairs huggingface dataset:
// 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.3101720329889768x):
#include <cstdio>

#include <cstdlib>

#include <iostream>

#include <cstring>

#include <cmath>

#include <ctime>

#include <algorithm>

#include <vector>

#include <set>

#include <queue>

#include <map>

#include <stack>

#include <bitset>

using namespace std;

typedef int gitype;

gitype gi () {

    gitype ret=0; char ch=getchar();

    while((ch<'0' || ch>'9') && ch!='-') ch=getchar();

    char c=ch=='-'?getchar():ch;

    while(c>='0' && c<='9') ret=ret*10+c-'0',c=getchar();

    return ch=='-'?-ret:ret;

}

const int N = 10010;

const int M = 100010;

int n,m,st[N],vis[N],dis[N],pt[M],nxt[M],w[M],c[M],cost[N],ent=0;

void link (int u,int v,int _w,int _c) {

    pt[++ent]=v; nxt[ent]=st[u]; st[u]=ent; w[ent]=_w; c[ent]=_c;

    pt[++ent]=u; nxt[ent]=st[v]; st[v]=ent; w[ent]=_w; c[ent]=_c;

}

queue<int> q;

int main () {

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

        memset(st,0,sizeof(st)); ent=0;

        int u,v,_w,_c;

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

            u=gi(); v=gi(); _w=gi(); _c=gi(); link(u,v,_w,_c);

        }

        for(int i=1;i<=n;i+=1) dis[i]=1e9 + 5;

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

        while(!q.empty()) {

            int r=q.front(); q.pop(); vis[r]=false;

            for(int i=st[r];i;i=nxt[i]) {

                if(dis[pt[i]] > dis[r]+w[i]) {

                    dis[pt[i]] = dis[r]+w[i]; cost[pt[i]] = c[i];

                    if(!vis[pt[i]]) {

                        vis[pt[i]] = true; q.push(pt[i]);

                    }

                } else if(dis[pt[i]] == dis[r]+w[i]) {

                    cost[pt[i]] = min(cost[pt[i]], c[i]);

                }

            }

        }

        int ans = 0;

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

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

    }

    return 0;

}
// 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: 1.2249846783633687x):
#include <cstdio>

#include <cstdlib>

#include <iostream>

#include <cstring>

#include <cmath>

#include <ctime>

#include <algorithm>

#include <vector>

#include <set>

#include <queue>

#include <map>

#include <stack>

#include <bitset>

using namespace std;

typedef int gitype;

gitype gi () {

    gitype ret=0; char ch=getchar();

    while((ch<'0' || ch>'9') && ch!='-') ch=getchar();

    char c=ch=='-'?getchar():ch;

    while(c>='0' && c<='9') ret=ret*10+c-'0',c=getchar();

    return ch=='-'?-ret:ret;

}

const int N = 10010;

const int M = 100010;

int n,m,st[N],vis[N],dis[N],pt[M],nxt[M],w[M],c[M],cost[N],ent=0;

void link (int u,int v,int _w,int _c) {

    pt[++ent]=v; nxt[ent]=st[u]; st[u]=ent; w[ent]=_w; c[ent]=_c;

    pt[++ent]=u; nxt[ent]=st[v]; st[v]=ent; w[ent]=_w; c[ent]=_c;

}

queue<int> q;

int main () {

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

        memset(st,0,sizeof(st)); ent=0;

        int u,v,_w,_c;

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

            u=gi(); v=gi(); _w=gi(); _c=gi(); link(u,v,_w,_c);

        }

        for(int i=1;i<=n;i+=1) dis[i]=1e9 + 5;

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

        while(!q.empty()) {

            int r=q.front(); q.pop(); vis[r]=false;

            for(int i=st[r];i;i=nxt[i]) {

                if(dis[pt[i]] > dis[r]+w[i]) {

                    dis[pt[i]] = dis[r]+w[i]; cost[pt[i]] = c[i];

                    if(!vis[pt[i]]) {

                        vis[pt[i]] = true; q.push(pt[i]);

                    }

                } else if(dis[pt[i]] == dis[r]+w[i]) {

                    cost[pt[i]] = min(cost[pt[i]], c[i]);

                }

            }

        }

        int ans = 0;

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

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

    }

    return 0;

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

#include <cstdlib>

#include <cstring>

#include <queue>

#include <algorithm>

using namespace std;

#define MAXN 10010

#define MAXM 40010



int n,m;

struct node

{

    int v,d,c,next;

}e[MAXM];

int ecnt,pre[MAXN],dis[MAXN],co[MAXN];

bool vis[MAXN];

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

{

    e[ecnt].v=v;

    e[ecnt].d=d;

    e[ecnt].c=c;

    e[ecnt].next=pre[u];

    pre[u]=ecnt++;

}

void spfa()

{

    queue<int> q;

    q.push(1);

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

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

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

    dis[1]=co[1]=0;

    while (!q.empty())

    {

        int u=q.front();

        q.pop();

        vis[u]=0;

        for (int i=pre[u];i!=-1;i=e[i].next)

        {

            int v=e[i].v;

            if ((dis[v]>dis[u]+e[i].d)||(dis[v]==dis[u]+e[i].d&&co[v]>e[i].c))

            {

                dis[v]=dis[u]+e[i].d;

                co[v]=e[i].c;

                if (!vis[v])

                {

                    vis[v]=1;

                    q.push(v);

                }

            }

        }

    }

}

int main()

{

    //freopen("/home/moor/Code/input","r",stdin);

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

    {

        ecnt=0;

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

        int u,v,d,c;

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

        }

        spfa();

        int ans=0;

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

            ans+=co[i];

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

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1173062973472154x):
#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;

}
// 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.5241545839696473x):
#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;

}
// 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.394509423058842x):
#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;

}
// 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: 1.3040854266980806x):
#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;

}
// 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.4599605520488128x):
#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;

}
// 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.5197061868239645x):
#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;

}