結果

問題 No.386 貪欲な領主
ユーザー 👑 horiesinitihoriesiniti
提出日時 2016-06-16 13:04:56
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 833 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 76,748 KB
実行使用メモリ 38,184 KB
最終ジャッジ日時 2024-04-20 07:25:11
合計ジャッジ時間 4,317 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:32:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
main.cpp:34:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |                 scanf("%d %d",&a,&b);
      |                 ~~~~~^~~~~~~~~~~~~~~
main.cpp:40:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |                 scanf("%d",&a);
      |                 ~~~~~^~~~~~~~~
main.cpp:44:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |         scanf("%d",&m);
      |         ~~~~~^~~~~~~~~
main.cpp:46:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |                 scanf("%d %d %d",&s,&g,&c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <vector>
std::map<int,std::set<int> > tree;
std::vector<int> cost;

int f(int oya,int p,int g,int sum){
	if (p==g){
		return sum+cost[p];
	}else{
		std::set<int>::iterator it;
		for(it=tree[p].begin();it!=tree[p].end();it++){
			int p2=(*it);
			int res=0;
			if (oya!=p2) {
				res=f(p,p2,g,sum+cost[p]);
			}
			if (res>0){
				return res;
			}
		}
	}
	return 0;
}


int main() {
	// your code goes here
	int n,a,b;
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		scanf("%d %d",&a,&b);
		tree[a].insert(b);
		tree[b].insert(a);
	}
	
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		cost.push_back(a);
	}
	int m,s,g,c,ans=0;
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		scanf("%d %d %d",&s,&g,&c);
		int t=f(-1,s,g,0);
		ans+=t*c;
	}
	printf("%d\n",ans);
	return 0;
}
0