#include #include #include #include using namespace std; const long long INF = numeric_limits::max(); // グラフの定義 struct Edge { int to; long long weight; }; void dijkstra(int start, const vector>& graph, vector& dist) { // 優先度付きキュー (最小ヒープ) priority_queue, vector>, greater<>> pq; dist[start] = 0; pq.push({0, start}); while (!pq.empty()) { auto [current_dist, current_vertex] = pq.top(); pq.pop(); // 最短距離が更新されていない場合はスキップ if (current_dist > dist[current_vertex]) continue; for (const auto& edge : graph[current_vertex]) { long long new_dist = current_dist + edge.weight; if (new_dist < dist[edge.to]) { dist[edge.to] = new_dist; pq.push({new_dist, edge.to}); } } } } int main() { int n, m, c; // 頂点数と辺数 cin >> n >> m >> c; vector a(n); for(int i = 0; i < n;i++)cin >> a[i]; vector> graph(n+1); for(int i = 0; i < n; i++){ graph[i].push_back({i+1, a[i]}); graph[i+1].push_back({i, a[i]}); } for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; u--; graph[u].push_back({v, c}); graph[v].push_back({u, c}); // 無向グラフの場合 } int start = 0; // 始点 vector dist(n+1, INF); dijkstra(start, graph, dist); long long asum = 0; // for(int i = 0; i < n + 1; i ++)cout << dist[i] << " "; // cout << endl; for(int i = 0; i < n; i++)asum += a[i]; cout << asum - dist[n] << endl; return 0; }