#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define stdI freopen("input.txt", "r", stdin);
#define stdO freopen("output.txt", "w", stdout);
#define all(x) x.begin(), x.end()
#define mp(x, y) make_pair(x, y)
#define int long long
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
template<typename T, template<typename> class order = less>
using ordered_set = tree<T,
null_type, order<T>, rb_tree_tag,
tree_order_statistics_node_update>;
typedef pair<int, int> pii;
const int MAXN = 32, MAXLOG = 18, MAXSQ = 500, INF = 1e18, MOD = 1e9 + 7;
vector<int> adj[MAXN];
map<int, int> fru[MAXN];
map<int, int> power[MAXN];
bool mk[MAXN];
int n, m, k, f;
void un(int u, int v)
{
int ru = u;
if(power[u].size() < power[v].size())
{
swap(u, v);
}
for(auto q : power[v])
{
power[u][q.F] += q.S;
}
if(ru != u)
{
swap(power[u], power[ru]);
}
}
void dfs(int v)
{
for(auto u : fru[v])
{
power[v][u.F] = u.S;
}
for(auto u : adj[v])
{
dfs(u);
un(v, u);
power[u].clear();
}
if(mk[v])
{
int mx = 0;
for(auto u : power[v])
{
mx = max(mx, u.S);
}
f += mx;
power[v].clear();
}
}
void solve()
{
cin >> n >> m >> k;
for(int i = 2; i <= n; i++)
{
int x; cin >> x;
adj[x].push_back(i);
}
for(int i = 0; i < m; i++)
{
int v, d, w; cin >> v >> d >> w;
fru[v][d]++;
}
int ans = 0;
for(int i = 0; i < (1 << n); i++)
{
memset(mk, 0, sizeof mk); f = 0;
int tmp = i;
if(tmp & 1)
{
continue;
}
while(tmp)
{
int q = __builtin_ctz(tmp);
tmp ^= (1 << q);
mk[q + 1] = 1;
}
dfs(1);
ans = max(ans, f);
}
cout << ans << "\n";
}
int32_t main()
{
IOS;
int t = 1;
//cin >> t;
while(t--)
{
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
592 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |