fork download
  1. // SRM 683, d2-hard, by Errichto
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. typedef long long ll;
  5. const int nax = 1e6 + 5;
  6. int a[nax];
  7. vector<int> w[nax];
  8. const int mod = 1e9 + 7;
  9. int answer;
  10.  
  11. int mul(int a, int b) { return (ll) a * b % mod; }
  12.  
  13. pair<int,int> dfs(int a, int par) {
  14. int pref = 1, ways = 1;
  15. for(int b : w[a]) if(b != par) {
  16. pair<int,int> tmp = dfs(b, a);
  17. pref = add(mul(pref, tmp.second), mul(ways, tmp.first));
  18. ways = mul(ways, tmp.second);
  19. }
  20. answer = add(answer, pref);
  21. return make_pair(pref, ways + 1);
  22. }
  23.  
  24. class SubtreesCounting {
  25. public : int sumOfSizes(int n, int a0, int b, int c, int m) {
  26. a[0] = a0;
  27. for(int i = 1; i <= n - 2; ++i)
  28. a[i] = ((ll) b * a[i-1] + c) % m;
  29. for(int i = 1; i <= n - 1; ++i) {
  30. int j = a[i-1] % i;
  31. // edge between i and j
  32. w[i].push_back(j);
  33. w[j].push_back(i);
  34. }
  35. dfs(0, -1);
  36. return answer;
  37. }
  38. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'std::pair<int, int> dfs(int, int)':
prog.cpp:17:57: error: 'add' was not declared in this scope
   pref = add(mul(pref, tmp.second), mul(ways, tmp.first));
                                                         ^
prog.cpp:20:27: error: 'add' was not declared in this scope
  answer = add(answer, pref);
                           ^
stdout
Standard output is empty