This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//In His Name
#include <bits/stdc++.h>
//#pragma GCC optimization("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
using namespace std;
#define ll long long
#define int ll
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
#define bug(x) cout << "Ah shit , here we go again : " << x <<endl
#define all(x) x.begin() , x.end()
const int maxn = 1e5 + 10, MOD = 1e9 + 7 ;
const ll INF = 1e18 + 100;
int n , m , k , v[maxn] ,d[maxn] , w[maxn] , dd[maxn];
vector<int> adj[maxn] , nums;
void Lis(){
vector<int> ans;
int N = nums.size();
for (int i = 0; i < N; i++) {
auto it = lower_bound(ans.begin(), ans.end(), nums[i]);
if (it == ans.end()) {
ans.push_back(nums[i]);
}
else {
*it = nums[i];
}
}
cout << ans.size();
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0) , cout.tie(0);
cin >> n >> m >> k;
bool ok = true;
for(int i = 2 ; i <= n ; i++){
int p;
cin >> p;
adj[p].pb(i);
if(p != i-1) ok = false;
}
int cnt = 0;
for(int i = 1 ; i <= m ; i++){
cin >> v[i] >> d[i] >> w[i];
dd[v[i]] = d[i];
cnt += w[i];
}
for(int i = n ; i > 1 ; i--) if(dd[i] != 0) nums.pb(dd[i]);
if(ok) Lis();
else cout << cnt;
}
# | 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... |