# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338419 | beksultan04 | Biochips (IZhO12_biochips) | C++14 | 33 ms | 47488 KiB |
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;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
const int N = 1e6+11,INF=1e9+7;
int n,m,tin[N],tout[N],cnt,ves[N],cot;
vector <int> gg[N],g[N];
void rec(int x){
tin[x]=++cnt;
int i;
for (i=0;i<gg[x].size();++i){
rec(gg[x][i]);
}
tout[x]=++cnt;
}
bool is_predok(int a,int b){
bool f = (tin[a] <= tin[b] && tout[a] > tout[b]);
swap(a,b);
f |= (tin[a] <= tin[b] && tout[a] > tout[b]);
ret f;
}
void dfs(int x,int cnt,int sum){
if (cnt == m){
cot = max(cot,sum);
}
int i;
for (i=0;i<g[x].size();++i){
dfs(g[x][i],cnt+1,sum+ves[g[x][i]]);
}
}
main(){
int i,j,s,cnt=1;
scan2(n,m)
for (i=1;i<=n;++i){
int x;
scan2(x,ves[i])
if (x == 0)s=i;
else
gg[x].pb(i);
}
rec(s);
for (i=1;i<=n;++i){
for (j=i+1;j<=n;++j){
if (!is_predok(i,j)){
g[i].pb(j);
}
}
}
for (i=1;i<=n;++i){
dfs(i,1,ves[i]);
}
cout <<cot;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |