結果
問題 |
No.2915 辺更新価値最大化
|
ユーザー |
|
提出日時 | 2024-10-04 22:16:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 1,802 bytes |
コンパイル時間 | 1,763 ms |
コンパイル使用メモリ | 170,664 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-04 22:16:04 |
合計ジャッジ時間 | 2,760 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long const int p=998244353; int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*1LL*u)%p;} else {int u=po(a,b-1);return (a*1LL*u)%p;}} int inv(int x) {return po(x,p-2);} mt19937 rnd; #define app push_back #define all(x) (x).begin(),(x).end() #ifdef LOCAL #define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__) #define debugv(v) do {cout<< #v <<" : {"; for(int izxc=0;izxc<v.size();++izxc) {cout << v[izxc];if(izxc+1!=v.size()) cout << ","; }cout <<"}"<< endl;} while(0) #else #define debug(...) #define debugv(v) #endif #define lob(a,x) lower_bound(all(a),x) #define upb(a,x) upper_bound(all(a),x) const int inf=1e18; const int maxn=1e3+5; vector<array<int,3> > v; bool ok[maxn]; int dp[maxn]; int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n,m,q;cin>>n>>m>>q; for(int i=0;i<m;++i) { int x,y,w;cin>>x>>y>>w;--x;--y; v.app({x,y,w}); } for(int i=0;i<m;++i) {ok[i]=1;} for(int i=0;i<q;++i) { int id;cin>>id;--id;ok[id]^=1; fill(dp,dp+maxn,-inf); dp[0]=0; while(true) { bool okk=false; for(int j=0;j<m;++j) { if(ok[j]) { auto h=v[j]; if(dp[h[1]]<dp[h[0]]+h[2]) { dp[h[1]]=dp[h[0]]+h[2]; okk=true; } } } if(!okk) {break;} } if(dp[n-1]<-1e12) { cout<<"NaN"<<'\n'; } else { cout<<dp[n-1]<<'\n'; } } return 0; }