結果
| 問題 |
No.1911 Alternately Coloring
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2022-04-22 22:45:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,186 bytes |
| コンパイル時間 | 1,134 ms |
| コンパイル使用メモリ | 93,624 KB |
| 最終ジャッジ日時 | 2025-01-28 20:34:23 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 WA * 4 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> using nega_queue = priority_queue<T, vector<T>, greater<T>>;
const i64 INF = 1001001001001001001;
int main(){
int N, M; cin >> N >> M;
vector<vector<int>> E(N);
rep(i,M){
int u,v; cin >> u >> v; u--; v--;
E[u].push_back(v);
E[v].push_back(u);
}
vector<int> A[2];
rep(t,2) A[t].resize(N);
rep(t,2) rep(i,N) cin >> A[t][i];
i64 ans = 0;
{
vector<int> C(N, -1);
C[0] = 0;
vector<int> bfs = {0};
rep(i,bfs.size()){
int p = bfs[i];
for(int e : E[p]) if(C[e] == -1){
bfs.push_back(e);
C[e] = C[p] ^ 1;
}
}
i64 sc[2] = {};
rep(i,N) rep(t,2) sc[t] = A[C[i]^t][i];
ans = max(sc[0], sc[1]);
}
vector<int> maxA(N);
rep(i,N) maxA[i] = max(A[0][i], A[1][i]);
i64 full = 0;
rep(i,N) full += maxA[i];
vector<vector<pair<int, int>>> adj(N*2);
vector<int> cost(N*2);
rep(t,2) rep(u,N) cost[N*t+u] = maxA[u] - A[t][u];
rep(u,N) for(int v : E[u]){
adj[u].push_back(make_pair(N+v, cost[N+v]));
adj[N+u].push_back(make_pair(v, cost[v]));
}
rep(s,N*2){
int t = (s+N) % (N*2);
vector<i64> D(N*2, INF);
nega_queue<pair<i64, int>> Que;
D[s] = 0;
Que.push(make_pair(D[s], s));
while(Que.size()){
auto [d,p] = Que.top(); Que.pop();
if(D[p] != d) continue;
for(auto [to, dd] : adj[p]){
i64 nxd = d + dd;
if(D[to] <= nxd) continue;
D[to] = nxd;
Que.push(make_pair(D[to], to));
}
}
ans = max(ans, full - D[t]);
}
cout << ans << '\n';
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia