結果
| 問題 | 
                            No.2604 Initial Motion
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-01-12 22:40:25 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,184 bytes | 
| コンパイル時間 | 1,493 ms | 
| コンパイル使用メモリ | 105,680 KB | 
| 実行使用メモリ | 330,916 KB | 
| 最終ジャッジ日時 | 2024-09-27 23:24:15 | 
| 合計ジャッジ時間 | 6,658 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 10 TLE * 1 -- * 28 | 
ソースコード
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cassert>
#include<atcoder/mincostflow>
using namespace std;
int K,N,M;
int A[2000],B[2000];
vector<pair<int,long> >G[2000];
long dist[2000];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>K>>N>>M;
	for(int i=0;i<K;i++)
	{
		int a;cin>>a;
		A[a-1]++;
	}
	for(int i=0;i<N;i++)cin>>B[i];
	for(int i=0;i<M;i++)
	{
		int u,v;
		long long d;
		cin>>u>>v>>d;
		u--,v--;
		G[u].push_back(make_pair(v,d));
		G[v].push_back(make_pair(u,d));
	}
	atcoder::mcf_graph<int,long>MF(N+N+2);
	int source=N+N,sink=N+N+1;
	for(int i=0;i<N;i++)
	{
		if(A[i]>0)MF.add_edge(source,i,A[i],0);
		if(B[i]>0)MF.add_edge(N+i,sink,B[i],0);
		for(int j=0;j<N;j++)dist[j]=1e18;
		priority_queue<pair<long,int> >Q;
		dist[i]=0;
		Q.push(make_pair(dist[i],i));
		while(!Q.empty())
		{
			int u=Q.top().second;
			long d=-Q.top().first;
			Q.pop();
			if(dist[u]<d)continue;
			MF.add_edge(i,N+u,K,d);
			for(pair<int,long>e:G[u])
			{
				int v=e.first;
				long nd=d+e.second;
				if(dist[v]>nd)
				{
					dist[v]=nd;
					Q.push(make_pair(-nd,v));
				}
			}
		}
	}
	cout<<MF.flow(source,sink,K).second<<endl;
}