結果
問題 | No.2915 辺更新価値最大化 |
ユーザー |
![]() |
提出日時 | 2024-10-06 18:05:33 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,793 ms / 2,000 ms |
コード長 | 1,833 bytes |
コンパイル時間 | 1,737 ms |
コンパイル使用メモリ | 125,704 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-06 18:05:43 |
合計ジャッジ時間 | 10,414 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#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>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> que; for(int j:p) if(can[j]>=-1e8) 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; } }