結果
| 問題 |
No.386 貪欲な領主
|
| コンテスト | |
| ユーザー |
horiesiniti
|
| 提出日時 | 2016-06-15 17:13:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 833 bytes |
| コンパイル時間 | 705 ms |
| コンパイル使用メモリ | 76,056 KB |
| 実行使用メモリ | 38,064 KB |
| 最終ジャッジ日時 | 2024-10-12 02:30:20 |
| 合計ジャッジ時間 | 4,362 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 11 |
コンパイルメッセージ
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);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
ソースコード
#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;
}
horiesiniti