結果

問題 No.899 γatheree
ユーザー latte0119
提出日時 2019-10-04 23:09:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,768 bytes
コンパイル時間 1,842 ms
コンパイル使用メモリ 170,004 KB
実行使用メモリ 17,276 KB
最終ジャッジ日時 2024-10-03 08:37:24
合計ジャッジ時間 11,083 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3 WA * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
      |               ~~~~~^~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#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=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;
}
}
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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0