結果

問題 No.1878 union-find の数え上げ
ユーザー Eki1009
提出日時 2022-03-18 21:34:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 364 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 195,592 KB
最終ジャッジ日時 2025-01-28 10:13:01
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~
main.cpp:16:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |     scanf("%d",&p);
      |     ~~~~~^~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
vector<int>G[1<<17];
const int mod=998244353;
int dfs(int u,int d){
  int res=1;
  for(int v:G[u])res=(long)res*dfs(v,d+1)%mod;
  if(d>=2)res++;
  return res;
}
int main(){
  int n;
  scanf("%d",&n);
  for(int i=1;i<n;i++){
    int p;
    scanf("%d",&p);
    p--;
    G[p].push_back(i);
  }
  printf("%d\n",dfs(0,0));
}
0