QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#871855 | #8127. Slučajna Cesta | Unforgettablepl# | 0 | 28ms | 10848kb | C++20 | 2.2kb | 2025-01-25 22:25:19 | 2025-01-25 22:25:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <int MOD=1000000007>
struct Modular {
int value;
static const int MOD_value = MOD;
Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}
Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}
friend Modular mexp(Modular a, long long e) {
Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
return res;
}
friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }
Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
friend Modular operator+(Modular a, Modular const b) { return a += b; }
friend Modular operator-(Modular a, Modular const b) { return a -= b; }
friend Modular operator-(Modular const a) { return 0 - a; }
friend Modular operator*(Modular a, Modular const b) { return a *= b; }
friend Modular operator/(Modular a, Modular const b) { return a /= b; }
friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};
int32_t main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<vector<int>> adj(n+1);
for(int i=1;i<n;i++){
int p;
cin >> p;
adj[i+1].emplace_back(p);
adj[p].emplace_back(i+1);
}
vector<Modular<>> v(n+1);
for(int i=1;i<=n;i++){
int a;cin>>a;
v[i]=a;
}
vector<Modular<>> Scores(n+1);
function<void(int,int)> dfs = [&](int x,int p){
Scores[x] = v[x];
for(int&j:adj[x])if(j!=p){
dfs(j,x);
Scores[x] += Scores[j]/Modular(adj[x].size());
}
};
dfs(1,0);
cout << v[1] + (Scores[1]-v[1])*Modular(adj[1].size())/Modular(adj[1].size()+1) << '\n';
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Acceptable Answer
time: 0ms
memory: 3712kb
input:
2 1 307903 536004
output:
575905
result:
points 0.50 the answer of the first question is correct, but there are mistakes in other answers.
Test #2:
score: 5
Acceptable Answer
time: 1ms
memory: 3712kb
input:
3 1 2 992649 690492 637324
output:
1497226
result:
points 0.50 the answer of the first question is correct, but there are mistakes in other answers.
Test #3:
score: 5
Acceptable Answer
time: 1ms
memory: 3584kb
input:
4 1 2 3 826918 524416 30987 233038
output:
501126006
result:
points 0.50 the answer of the first question is correct, but there are mistakes in other answers.
Test #4:
score: 5
Acceptable Answer
time: 0ms
memory: 3584kb
input:
5 1 2 3 4 859332 957641 552087 294350 114098
output:
126520100
result:
points 0.50 the answer of the first question is correct, but there are mistakes in other answers.
Test #5:
score: 0
Wrong Answer
time: 0ms
memory: 3584kb
input:
6 1 2 2 4 5 91742 92552 191745 529457 181043 884683
output:
41976834
result:
wrong answer first question answered incorrectly
Subtask #2:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 1ms
memory: 3584kb
input:
100 1 2 1 4 5 6 7 7 9 9 5 12 5 4 1 16 17 18 18 20 20 22 23 24 25 23 27 28 27 30 31 32 27 34 35 36 37 38 39 39 41 38 43 43 45 46 43 48 49 49 49 48 48 54 55 56 57 57 55 60 60 62 55 64 65 64 67 67 69 69 69 72 37 74 75 76 76 78 76 80 81 82 80 84 85 74 87 87 89 89 91 89 87 94 94 96 97 98 98 754341 720186...
output:
723109644
result:
wrong answer first question answered incorrectly
Subtask #3:
score: 0
Wrong Answer
Test #54:
score: 0
Wrong Answer
time: 28ms
memory: 7936kb
input:
60000 1 2 2 1 3 4 5 6 9 6 11 11 13 8 4 10 7 10 3 16 12 9 19 15 24 24 27 25 8 16 13 7 20 15 22 28 33 31 20 27 41 17 25 35 39 5 22 34 19 14 49 34 51 31 39 56 55 48 48 14 47 50 58 12 61 41 66 21 62 64 57 32 54 30 30 50 45 40 56 38 38 43 76 44 84 49 59 84 66 45 57 60 47 42 33 54 74 37 59 26 18 101 80 67...
output:
10091936
result:
wrong answer first question answered incorrectly
Subtask #4:
score: 0
Wrong Answer
Test #79:
score: 0
Wrong Answer
time: 28ms
memory: 10848kb
input:
100000 1 1 3 4 5 6 7 8 9 10 9 12 13 14 15 14 12 8 19 20 21 20 19 24 24 26 26 28 29 26 31 26 33 34 26 36 36 38 39 40 41 36 4 44 45 46 47 47 49 44 51 52 53 54 53 52 57 58 59 60 61 61 63 61 65 66 67 67 69 70 69 72 59 74 74 76 76 78 79 78 81 82 83 84 85 82 87 87 58 90 91 92 93 91 95 51 97 98 99 99 101 1...
output:
230930264
result:
wrong answer first question answered incorrectly