結果

問題 No.17 2つの地点に泊まりたい
ユーザー myantamyanta
提出日時 2017-05-01 12:51:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 545 ms / 5,000 ms
コード長 1,493 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 50,816 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 02:18:23
合計ジャッジ時間 2,900 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,948 KB
testcase_04 AC 12 ms
6,940 KB
testcase_05 AC 141 ms
6,944 KB
testcase_06 AC 85 ms
6,944 KB
testcase_07 AC 32 ms
6,940 KB
testcase_08 AC 380 ms
6,940 KB
testcase_09 AC 545 ms
6,940 KB
testcase_10 AC 38 ms
6,944 KB
testcase_11 AC 92 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 116 ms
6,940 KB
testcase_24 AC 82 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 251 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:80:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   80 |                         scanf("%d", &point[i].s);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:82:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   82 |                 scanf("%d", &m);
      |                 ~~~~~^~~~~~~~~~
main.cpp:85:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   85 |                         scanf("%d%d%d", &a, &b, &c);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<cstdio>
#include<vector>
#include<queue>


using namespace std;


typedef long long ll;


struct road_t
{
	int to, c;
};


struct point_t
{
	int s;
	vector<road_t> road;
};


int min_u(int& m, int v)
{
	if(m>v || m<0)
	{
		m=v;
		return 1;
	}
	return 0;
}


void solve(vector<point_t>& point, vector<vector<int> >& state, int stay_prev, int cur_p, int cur_c)
{
	if(!min_u(state[stay_prev][cur_p], cur_c)) return;
	int n=point.size();

	if(cur_p!=0 && cur_p!=n-1 && stay_prev<n && stay_prev!=cur_p)
	{
		int nc=cur_c+point[cur_p].s;
		int idx=cur_p;

		if(stay_prev>0) idx=n;
		if(state[idx][cur_p]<0 || state[idx][cur_p]>nc)
		{
			solve(point, state, idx, cur_p, nc);
		}
	}

	for(auto r: point[cur_p].road)
	{
		solve(point, state, stay_prev, r.to, cur_c+r.c);
	}
}


int main(void)
{
	int n, m, i, a, b, c;
	vector<point_t> point;
	vector<vector<int> > state;

	while(scanf("%d", &n)==1)
	{
		point.clear();
		point.resize(n);

		state.resize(n+1);
		for(i=0;i<state.size();i++)
		{
			state[i].resize(n);
			fill(state[i].begin(), state[i].end(), -1);
		}

		for(i=0;i<n;i++)
		{
			scanf("%d", &point[i].s);
		}
		scanf("%d", &m);
		for(i=0;i<m;i++)
		{
			scanf("%d%d%d", &a, &b, &c);
			point[a].road.push_back((road_t){b, c});
			point[b].road.push_back((road_t){a, c});
		}

		solve(point, state, 0, 0, 0);
/*
		for(int j=0;j<state.size();j++)
		{
			for(int i=0;i<n;i++) printf("%3d ", state[j][i]);
			printf("\n");
		}
*/
		printf("%d\n", state[n][n-1]);
	}

	return 0;
}
0