結果

問題 No.417 チューリップバブル
ユーザー myantamyanta
提出日時 2017-05-31 08:23:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,419 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 60,912 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 18:59:39
合計ジャッジ時間 2,051 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
4,348 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 1 ms
4,348 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:93:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   93 |                 for(int i=0;i<n;i++) scanf("%d", &u[i]);
      |                                      ~~~~~^~~~~~~~~~~~~
main.cpp:99:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   99 |                         scanf("%d%d%d", &a, &b, &c);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

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


using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vpii=vector<pii>;
using vvpii=vector<vpii>;


struct q_t
{
	int p, r, c;
	vi f;
	bool operator<(const q_t& rhs) const
	{
		return c>rhs.c;
	}
};


class pq_t
{
	priority_queue<q_t> q;
public:
	void push(int p, int r, int c, vi& f)
	{
		q.push((q_t){p, r, c, f});
	}
	int pop(int&p, int&r, int&c, vi&f)
	{
		if(q.empty()) return 0;
		auto t=q.top();
		q.pop();
		p=t.p;
		r=t.r;
		c=t.c;
		f=t.f;
		return 1;
	}
};


int solve(vvpii& v, vi& u, int m)
{
	int n=v.size();
	vi f;
	int p=0, r=u[0], c=m, ret=-1;
	pq_t q;

	f.resize(n);

	f[0]=1;
	q.push(p, r, c, f);
	while(q.pop(p, r, c, f))
	{
//printf("p=%d r=%d c=%d\n", p, r, c);
		if(c<0) break;
		if(ret<r) ret=r;

		for(int i=0;i<v[p].size();i++)
		{
			int np, nr, nc;
			np=v[p][i].first;
			nc=c-v[p][i].second*2;
			if(f[np]) continue;

			f[np]=1;
			nr=r+u[np];
			q.push(np, nr, nc, f);
			f[np]=0;
		}
	}
	return ret;
}


int main(void)
{
	int n, m;
	vi u;
	vvpii v;

	while(scanf("%d%d", &n, &m)==2)
	{
		v.clear();
		v.resize(n);
		u.resize(n);
		for(int i=0;i<n;i++) scanf("%d", &u[i]);

		for(int i=0;i<n-1;i++)
		{
			int a, b, c;

			scanf("%d%d%d", &a, &b, &c);
			v[a].push_back(make_pair(b, c));
			v[b].push_back(make_pair(a, c));
		}
		printf("%d\n", solve(v, u, m));
	}

	return 0;
}
0