This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<vector<int>> adj(n);
vector<ll> weight(n);
vector<int> day(n);
bool isLine = true;
for(int i = 1; i < n; i++) {
int x;
cin >> x;
x--;
adj[i].push_back(x);
adj[x].push_back(i);
if(x != i-1) isLine = false;
}
int maxWeight = -1, maxDay = -1, maxAdj = -1;
for(int i = 0; i < m; i++) {
int v, d, w;
cin >> v >> d >> w;
v--;
weight[v] = w;
day[v] = d;
maxWeight = max(maxWeight, w);
maxDay = max(maxDay, d);
maxAdj = max(maxAdj, (int)adj[v].size());
}
ll ans = 0;
if(isLine && maxWeight == 1) { // Longest increasing subsequence
reverse(day.begin(), day.end());
vector<int> day2;
for(int d : day) if(d) day2.push_back(d);
map<int, int> m;
m[0] = 0;
for(int i = 0; i < day2.size(); i++) {
int w = day2[i];
auto p = m.upper_bound(w);
p--;
m[w] = (*p).second + 1;
}
for(auto p : m) {
ans = max(ans, (ll)p.second);
}
}
else if(n <= 20 && k <= 20 && maxWeight == 1) {
}
else if(maxAdj == 1) {
for(int w : weight) ans += w;
}
else if(k <= 2) {
}
else if(k <= 20 && maxAdj == 1) {
}
else if(m <= 1000) {
}
else if(maxWeight == 1) {
}
else {
}
cout << ans << '\n';
}
Compilation message (stderr)
magictree.cpp: In function 'int main()':
magictree.cpp:39:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i = 0; i < day2.size(); i++) {
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |