优先级队列直接AC。
/* 2388 */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 typedef struct node_t {
int u, w; node_t() {}
node_t(int u, int w):
u(u), w(w) {} friend bool operator< (const node_t& a, const node_t& b) {
return a.w > b.w;
} } node_t; typedef struct {
int v, w, nxt;
} edge_t; const int INF = 0x3f3f3f3f;
const int maxv = 1e5+;
const int maxe = 2e5+;
edge_t E[maxe];
int head[maxv], l;
int W[maxv];
int dis[maxv];
bool visit[maxv];
int n, m; void init() {
memset(head, -, sizeof(head));
l = ;
} void addEdge(int u, int v, int wa, int wb) {
E[l].v = v;
E[l].w = wa;
E[l].nxt = head[u];
head[u] = l++; E[l].v = u;
E[l].w = wb;
E[l].nxt = head[v];
head[v] = l++;
} int bfs() {
priority_queue<node_t> Q;
node_t nd;
int u, v, w; // memset(dis, INF, sizeof(dis));
memset(visit, false, sizeof(visit));
rep(i, , n) {
Q.push(node_t(i, W[i]));
dis[i] = W[i];
} while (!Q.empty()) {
nd = Q.top();
Q.pop();
if (visit[nd.u])
continue;
visit[u=nd.u] = true;
for (int k=head[u]; k!=-; k=E[k].nxt) {
v = E[k].v;
if (dis[v] > dis[u]+E[k].w) {
dis[v] = dis[u] + E[k].w;
Q.push(node_t(v, dis[v]));
}
}
} int ret = ;
rep(i, , n)
if (dis[i] > dis[ret])
ret = i; return ret;
} void solve() {
int ans = bfs(); printf("%d\n\n", ans);
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int t;
int u, v, wa, wb; scanf("%d", &t);
rep(tt, , t+) {
scanf("%d %d", &n, &m);
init();
rep(i, , n)
scanf("%d", &W[i]);
rep(i, , m) {
scanf("%d %d %d %d", &u, &v, &wa, &wb);
addEdge(u, v, wa, wb);
}
printf("Scenario #%d:\n", tt);
solve();
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}