結果
| 問題 |
No.2915 辺更新価値最大化
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2024-10-06 18:01:51 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,813 bytes |
| コンパイル時間 | 1,602 ms |
| コンパイル使用メモリ | 125,844 KB |
| 実行使用メモリ | 13,640 KB |
| 最終ジャッジ日時 | 2024-10-06 18:02:10 |
| 合計ジャッジ時間 | 7,143 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 8 TLE * 1 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
#include<queue>
#include<atcoder/scc>
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n,m,q;
cin>>n>>m>>q;
vector<vector<int>> g(n);
vector<ll> u(m),v(m),w(m);
for(int i = 0;i<m;i++){
cin>>u[i]>>v[i]>>w[i];
u[i]--;v[i]--;
g[u[i]].push_back(i);
}
vector<int> now(m,0);
while(q--){
{
int j;
cin>>j;
j--;
now[j] ^= 1;
}
atcoder::scc_graph s(n);
{
for(int i = 0;i<m;i++) if(now[i]==0) s.add_edge(u[i],v[i]);
}
auto use = s.scc();
vector<int> cnt(n,0);
for(int i = 0;i<use.size();i++) for(int j:use[i]) cnt[j] = i;
vector<ll> can(n,-1e18);
can[0] = 0;
for(auto p:use){
priority_queue<pair<ll,ll>> que;
for(int j:p) if(can[j]!=-1e18) que.push({can[j],j});
while(que.size()){
int ni = que.top().second;
auto nn = que.top();
que.pop();
if(nn.first!=can[ni]) continue;
for(auto id:g[ni]){
int to = v[id];
if(now[id]==1) continue;
if(cnt[to]==cnt[ni]){
if(can[to]<can[ni]+w[id]){
can[to] = can[ni] + w[id];
que.push({can[to],to});
}
}else{
can[to] = max(can[to],can[ni]+w[id]);
}
}
}
}
ll ans = can[n-1];
if(ans<-1e8) cout<<"Nan\n";
else cout<<ans<<endl;
//return 0;
}
}
momoyuu