#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 100;
vector<int> a[MAXN];
int v[MAXN];
int w[MAXN];
int d[MAXN];
int n, m, k;
int par[MAXN];
int outdegree[MAXN];
namespace sub1{
bool check(){
return n <= 20 && k <= 20;
}
int mark[21];
bool flag = true;
void dfs(int u, int t){
if (mark[u]){
if (d[u] > t){
flag = false;
}
}
for (int v: a[u]){
dfs(v, (mark[u] ? d[u]: t));
}
}
void solve(){
long long ans = 0;
for (int mask = 0; mask < (1 << m); mask++){
memset(mark, 0, sizeof(mark));
long long cnt = 0;
for (int i = 0; i < m; i++){
if (mask & (1 << i)){
mark[v[i + 1]] = true;
cnt += w[i + 1];
}
}
flag = true;
dfs(1, 1e9);
if (flag){
for (int i = 0; i < m; i++){
if (mask & (1 << i)){
cout << i + 1 << " ";
}
}
cout << '\n';
ans = max(ans, cnt);
}
}
cout << ans << '\n';
}
}
namespace sub2{
bool check(){
for (int i = 1; i <= m; i++){
if (outdegree[v[i]] != 0) return 0;
}
return 1;
}
void solve(){
long long ans = 0;
for (int i = 1; i <= m; i++){
ans += w[i];
}
cout << ans << '\n';
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 2; i <= n; i++){
int x;
cin >> x;
a[x].push_back(i);
outdegree[x]++;
}
for (int i = 1; i <= m; i++){
cin >> v[i] >> d[i] >> w[i];
}
if (sub1::check()) sub1::solve();
else if (sub2::check()) sub2::solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
5980 KB |
Output is correct |
2 |
Correct |
15 ms |
6884 KB |
Output is correct |
3 |
Correct |
30 ms |
7252 KB |
Output is correct |
4 |
Correct |
21 ms |
6360 KB |
Output is correct |
5 |
Correct |
27 ms |
7000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
7768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
3356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |