結果
問題 |
No.3111 Toll Optimization
|
ユーザー |
![]() |
提出日時 | 2025-04-18 20:10:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 519 ms / 5,000 ms |
コード長 | 811 bytes |
コンパイル時間 | 5,020 ms |
コンパイル使用メモリ | 267,516 KB |
実行使用メモリ | 249,460 KB |
最終ジャッジ日時 | 2025-04-18 20:10:38 |
合計ジャッジ時間 | 24,475 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001LL int main(){ int n,m,k; cin>>n>>m>>k; mcf_graph<int,long long> G(n*(k+1)); rep(i,n){ rep(j,k){ G.add_edge(i*(k+1)+j,i*(k+1)+j+1,1,0); } } vector<long long> a(m),b(m),c(m); rep(i,m)cin>>c[i]; rep(i,m){ cin>>a[i]>>b[i]; a[i]--,b[i]--; } rep(i,m){ rep(_,2){ rep(j,k+1){ G.add_edge(a[i]*(k+1)+j,b[i]*(k+1)+j,1,c[i]); if(j!=k){ G.add_edge(a[i]*(k+1)+j,b[i]*(k+1)+j+1,1,0); } } swap(a[i],b[i]); } } auto ans = G.flow(0,n*(k+1)-1,1); if(ans.first==0)cout<<-1<<endl; else cout<<ans.second<<endl; return 0; }