結果

問題 No.17 2つの地点に泊まりたい
ユーザー ciel
提出日時 2015-07-08 23:23:59
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 740 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 41,600 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 01:23:39
合計ジャッジ時間 1,274 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
main.cpp:11:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |                 scanf("%d",&cost[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~
main.cpp:16:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         scanf("%d",&m);
      |         ~~~~~^~~~~~~~~
main.cpp:19:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |                 scanf("%d%d%d",&a,&b,&c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <vector>
#include <cstdio>
using namespace std;

int main(){
	int n,m;
	scanf("%d",&n);
	vector<int>cost(n);
	vector<vector<long long> >dist(n);
	for(int i=0;i<n;i++){
		scanf("%d",&cost[i]);
		dist[i].resize(n);
		for(int j=0;j<n;j++)dist[i][j]=1LL<<61;
		dist[i][i]=0;
	}
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		dist[a][b]=dist[b][a]=c;
	}
	for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)
		if(dist[i][j]>dist[i][k]+dist[k][j])dist[i][j]=dist[i][k]+dist[k][j];
	long long ma=1LL<<61;
	for(int i=1;i<n-1;i++)for(int j=1;j<n-1;j++)
		if(i!=j&&ma>dist[0][i]+cost[i]+dist[i][j]+cost[j]+dist[j][n-1])ma=dist[0][i]+cost[i]+dist[i][j]+cost[j]+dist[j][n-1];
	printf("%lld\n",ma);
}
0