原题链接:
https://www.nowcoder.com/practice/e372b623d0874ce2915c663d881a3ff2?tpId=40&tqId=21483&tPage=1&rp=1&ru=/ta/kaoyan&qru=/ta/kaoyan/question-ranking
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
const int inf = 0x3f3f3f3f;
typedef long long ll;
typedef unsigned long long ull;
const ll N = 1e3;
const ll MAXN = 1e6+10;
const ll mod = 1e5;
struct E
{
int next;
int c;
int cost;
};
vector<E> edge[N];
int dis[N];
int cost[N];
bool mark[N];
int main()
{
int n, m;
int S, T;
while(cin >> n >> m)
{
if(n == 0 && m == 0) break;
for(int i=1; i<=n; i++) edge[i].clear();
while(m--)
{
int a, b, c, cost;
cin >> a >> b >> c >> cost;
E tmp;
tmp.c = c;
tmp.cost = cost;
tmp.next = b;
edge[a].push_back(tmp);
tmp.next = a;
edge[b].push_back(tmp);
}
cin >> S >> T;
for(int i=1; i<=n; i++)
{
dis[i] = -1;
mark[i] = false;
}
dis[S] = 0;
mark[S] = true;
int newP = S;
for(int i=1; i < n; i++)
{
for(int j=0; j<edge[newP].size(); j++)
{
int t = edge[newP][j].next;
int c = edge[newP][j].c;
int co = edge[newP][j].cost;
if(mark[t] == true) continue;
if(dis[t] == -1 || dis[t] > dis[newP] + c || dis[t] == dis[newP] + c && cost[t] > cost[newP] + co)
{
dis[t] = dis[newP] + c;
cost[t] = cost[newP] + co;
}
}
int temp = inf;
for(int j=1; j <= n; j++)
{
if(mark[j] == true) continue;
if(dis[j] == -1) continue;
if(dis[j] < temp)
{
temp = dis[j];
newP = j;
}
}
mark[newP] = true;
}
cout << dis[T] << ' ' << cost[T] << endl;
}
}