結果

問題 No.2604 Initial Motion
ユーザー kotatsugamekotatsugame
提出日時 2024-01-12 22:40:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,184 bytes
コンパイル時間 1,404 ms
コンパイル使用メモリ 105,808 KB
実行使用メモリ 332,580 KB
最終ジャッジ日時 2024-01-12 22:40:37
合計ジャッジ時間 6,961 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 66 ms
16,664 KB
testcase_04 AC 72 ms
16,664 KB
testcase_05 AC 64 ms
16,664 KB
testcase_06 AC 65 ms
16,664 KB
testcase_07 AC 67 ms
16,664 KB
testcase_08 AC 73 ms
16,664 KB
testcase_09 AC 65 ms
16,664 KB
testcase_10 AC 66 ms
16,664 KB
testcase_11 AC 66 ms
16,664 KB
testcase_12 AC 64 ms
16,664 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0