結果
| 問題 |
No.2321 Continuous Flip
|
| コンテスト | |
| ユーザー |
ぷら
|
| 提出日時 | 2023-07-26 03:54:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 253 ms / 2,000 ms |
| コード長 | 1,438 bytes |
| コンパイル時間 | 2,146 ms |
| コンパイル使用メモリ | 205,188 KB |
| 最終ジャッジ日時 | 2025-02-15 19:11:23 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
long long inf = 1001001001001001001;
bool chmin(long long &x,long long y) {
if(x > y) {
x = y;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M,C;
cin >> N >> M >> C;
vector<int>A(N);
long long sum = 0;
for(int i = 0; i < N; i++) {
cin >> A[i];
sum += A[i];
}
vector<vector<int>>road(N+1);
for(int i = 0; i < M; i++) {
int L,R;
cin >> L >> R;
L--;
road[L].push_back(R);
road[R].push_back(L);
}
vector<long long>dist(N+1,inf);
dist[0] = 0;
priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>>que;
que.push({0,0});
while(!que.empty()) {
auto a = que.top();
que.pop();
if(dist[a.second] != a.first) continue;
for(auto i:road[a.second]) {
if(chmin(dist[i],a.first+C)) {
que.push({dist[i],i});
}
}
if(a.second < N) {
if(chmin(dist[a.second+1],a.first+A[a.second])) {
que.push({dist[a.second+1],a.second+1});
}
}
if(a.second) {
if(chmin(dist[a.second-1],a.first+A[a.second-1])) {
que.push({dist[a.second-1],a.second-1});
}
}
}
cout << sum-dist[N] << "\n";
}
ぷら