結果
問題 | No.899 γatheree |
ユーザー |
![]() |
提出日時 | 2019-10-04 23:03:10 |
言語 | C++11 (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,760 bytes |
コンパイル時間 | 1,606 ms |
コンパイル使用メモリ | 169,856 KB |
実行使用メモリ | 14,592 KB |
最終ジャッジ日時 | 2024-10-03 08:25:35 |
合計ジャッジ時間 | 9,760 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | RE * 23 |
コンパイルメッセージ
main.cpp: In function ‘void calc(long long int)’: main.cpp:48:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 48 | rep(i,q)scanf("%lld",&x[i]); | ~~~~~^~~~~~~~~~~~~~ main.cpp: In function ‘int main()’: main.cpp:90:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 90 | scanf("%lld",&N); | ~~~~~^~~~~~~~~~~ main.cpp:93:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 93 | scanf("%lld%lld",&a,&b); | ~~~~~^~~~~~~~~~~~~~~~~~ main.cpp:96:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 96 | rep(i,N)scanf("%lld",&A[i]); | ~~~~~^~~~~~~~~~~~~~ main.cpp:100:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 100 | 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;} 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){ if(dep[a]<dep[b])swap(a,b); if(par[a]==b)return true; if(par[a]==par[b])return true; if(dep[a]>=2&&par[par[a]]==b)return true; return false; } 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[x[i]][0]!=-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=10; rep(j,3)if(who[j][i]!=-1)chmin(k,who[j][i]); if(k==10)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; } } printf("%lld\n",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)); } return 0; }