結果
| 問題 |
No.2604 Initial Motion
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-01-12 22:05:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,664 bytes |
| コンパイル時間 | 2,385 ms |
| コンパイル使用メモリ | 194,944 KB |
| 実行使用メモリ | 340,536 KB |
| 最終ジャッジ日時 | 2024-09-27 22:22:40 |
| 合計ジャッジ時間 | 7,816 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 TLE * 1 -- * 28 |
ソースコード
// Problem: No.2604 Initial Motion
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2604
// Memory Limit: 512 MB
// Time Limit: 3000 ms
#include<bits/stdc++.h>
#include <atcoder/mincostflow>
#define debug(x) cerr<<(#x)<<" "<<(x)<<endl
using namespace atcoder;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void write(ll x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
}
const ll N=2e3+5,INF=1e18;
ll n,m,S,T;
ll dis[N],ok[N],a[N],b[N],k;
vector<pii>to[N];
int main(){
k=read(),n=read(),m=read();
rep(i,1,k)a[i]=read();
rep(i,1,n)b[i]=read();
rep(i,1,m){
ll x=read(),y=read(),z=read();
to[x].push_back(make_pair(y,z));
to[y].push_back(make_pair(x,z));
}
mcf_graph<ll, ll> g(n+k+2);
ll S = 0, T= n+k+1;
rep(i,1,k){
rep(j,1,n)dis[j]=INF,ok[j]=0;
dis[a[i]]=0;
priority_queue<pii>q;
q.push(make_pair(0,a[i]));
while(!q.empty()){
pii now=q.top();q.pop();
ll u=now.second;
if(ok[u])continue;
ok[u]=1;
for(pii es:to[u]){
ll v=es.first,w=es.second;
if(dis[v]>dis[u]+w){
dis[v]=dis[u]+w;
q.push(make_pair(-dis[v],v));
}
}
}
rep(j,1,n){
if(b[j])g.add_edge(i,j+k,1,dis[j]);
}
g.add_edge(S,i,1,0);
}
rep(i,1,n){
if(b[i])g.add_edge(i+k,T,b[i],0);
}
pii result = g.flow(S,T, INF);
write(result.second);
return 0;
}