#include #include #include #include #include using namespace std; const long long INF = 1e18; struct Edge { int to; long long cost; }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, M; if (!(cin >> N >> M)) return 0; vector P(N + 1); for (int i = 1; i <= N; ++i) { cin >> P[i]; } vector> adj(N + 1); for (int i = 0; i < M; ++i) { int u, v; long long t; cin >> u >> v >> t; adj[u].push_back({v, t}); } // P_i が小さい順に頂点を並び替える vector nodes(N); iota(nodes.begin(), nodes.end(), 1); sort(nodes.begin(), nodes.end(), [&](int a, int b) { return P[a] < P[b]; }); long long min_total_cost = INF; long long min_count = 0; // 上位 K 個(ここでは 50 個)だけを始点として探索する(嘘!) int K = min(N, 50); for (int i = 0; i < K; ++i) { int start = nodes[i]; vector dist(N + 1, INF); vector in_queue(N + 1, false); queue q; dist[start] = 0; q.push(start); in_queue[start] = true; while (!q.empty()) { int u = q.front(); q.pop(); in_queue[u] = false; for (auto& edge : adj[u]) { int v = edge.to; long long weight = edge.cost; if (dist[u] + weight < dist[v]) { dist[v] = dist[u] + weight; if (!in_queue[v]) { q.push(v); in_queue[v] = true; } } } } for (int v = 1; v <= N; ++v) { if (start == v || dist[v] == INF) continue; long long current_cost = dist[v] + P[start] + P[v]; if (current_cost < min_total_cost) { min_total_cost = current_cost; min_count = 1; } else if (current_cost == min_total_cost) { min_count++; } } } if (min_total_cost == INF) cout << -1 << "\n"; else cout << min_total_cost << " " << min_count << "\n"; return 0; }