結果
問題 | No.899 γatheree |
ユーザー | latte0119 |
提出日時 | 2019-10-04 23:47:18 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,778 bytes |
コンパイル時間 | 1,635 ms |
コンパイル使用メモリ | 171,656 KB |
実行使用メモリ | 17,152 KB |
最終ジャッジ日時 | 2024-10-03 09:53:22 |
合計ジャッジ時間 | 13,488 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
8,960 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
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 | AC | 1,684 ms
17,152 KB |
testcase_22 | AC | 1,688 ms
17,152 KB |
testcase_23 | AC | 1,829 ms
17,152 KB |
コンパイルメッセージ
main.cpp: In function ‘void calc(long long int)’: main.cpp:52:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 52 | rep(i,q)scanf("%lld",&x[i]); | ~~~~~^~~~~~~~~~~~~~ main.cpp: In function ‘int main()’: main.cpp:94:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 94 | scanf("%lld",&N); | ~~~~~^~~~~~~~~~~ main.cpp:97:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 97 | scanf("%lld%lld",&a,&b); | ~~~~~^~~~~~~~~~~~~~~~~~ main.cpp:100:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 100 | rep(i,N)scanf("%lld",&A[i]); | ~~~~~^~~~~~~~~~~~~~ main.cpp:104:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 104 | int Q;scanf("%lld",&Q); | ~~~~~^~~~~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define all(v) (v).begin(),(v).end() #define fi first #define se second typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;} template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;} const int B=400; int N; vint G[111111]; int who[3][111111]; int A[111111]; int par[111111],dep[111111]; void dfs(int v,int p,int d){ par[v]=p; dep[v]=d; for(auto u:G[v]){ if(u==p)continue; dfs(u,v,d+1); } } inline bool isok(int a,int b){ rep(i,2){ if(dep[a]<dep[b])swap(a,b); a=par[a]; if(a==b)return true; } return false; } vint anslis; void calc(int q){ vint x(q); rep(i,q)scanf("%lld",&x[i]); memset(who,-1,sizeof(who)); queue<pint>que; rep(i,q){ if(who[0][x[i]]!=-1)continue; who[0][x[i]]=i; que.push(pint(0,x[i])); } while(que.size()){ int d,v; tie(d,v)=que.front(); que.pop(); if(d==2)continue; for(auto u:G[v]){ if(who[d+1][u]!=-1)continue; who[d+1][u]=who[d][v]; que.push(pint(d+1,u)); } } rep(i,N){ int k=1000000; rep(j,3)if(who[j][i]!=-1)chmin(k,who[j][i]); if(k==1000000)continue; if(x[k]==i)continue; A[x[k]]+=A[i]; A[i]=0; } rep(i,q){ for(int j=0;j<i;j++){ if(x[j]!=x[i]&&isok(x[j],x[i])){ A[x[i]]+=A[x[j]]; A[x[j]]=0; } } anslis.pb(A[x[i]]); } } signed main(){ scanf("%lld",&N); rep(i,N-1){ int a,b; scanf("%lld%lld",&a,&b); G[a].pb(b);G[b].pb(a); } rep(i,N)scanf("%lld",&A[i]); dfs(0,-1,0); int Q;scanf("%lld",&Q); for(int i=0;i<Q;i+=B){ calc(min(Q-i,B)); } rep(i,Q){ printf("%lld\n",anslis[i]); } return 0; }