Submission #256297

# Submission time Handle Problem Language Result Execution time Memory
256297 2020-08-02T13:53:48 Z uacoder123 Biochips (IZhO12_biochips) C++14
0 / 100
2000 ms 113288 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))

typedef  long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int arr[200001][501]={};
int n,m;
vi al[200001];
int val[200001];
void dfs(int node,int p)
{
  for(int i=0;i<al[node].size();++i)
    if(al[node][i]!=p)
      dfs(al[node][i],node);
  arr[node][0]=0;
  for(int i=0;i<al[node].size();++i)
  {
    if(al[node][i]!=p)
    {
      for(int j=m;j>=0;--j)
      {
        for(int k=0;k<=j;++k)
        {
          if((arr[node][j-k]!=0||j-k==0)&&(arr[al[node][i]][k]!=0||k==0))
            arr[node][j]=max(arr[node][j],arr[node][j-k]+arr[al[node][i]][k]);
        }
      }
    }
  }
  arr[node][1]=max(val[node],arr[node][1]);
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin>>n>>m;
  int r;
  for(int i=1;i<=n;++i)
  {
    int f,w;
    cin>>f>>w;
    if(f!=0)
    {
      al[f].pb(i);
      al[i].pb(f);
    }
    else
      r=i;
    val[i]=w;
  }
  dfs(r,r);
  cout<<arr[r][m]<<endl;
  return(0);
}

Compilation message

biochips.cpp: In function 'void dfs(int, int)':
biochips.cpp:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<al[node].size();++i)
               ~^~~~~~~~~~~~~~~~
biochips.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<al[node].size();++i)
               ~^~~~~~~~~~~~~~~~
biochips.cpp: In function 'int main()':
biochips.cpp:66:17: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   cout<<arr[r][m]<<endl;
                 ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5120 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 5248 KB Output is correct
4 Correct 36 ms 22904 KB Output is correct
5 Correct 62 ms 25080 KB Output is correct
6 Correct 87 ms 25080 KB Output is correct
7 Execution timed out 2080 ms 113288 KB Time limit exceeded
8 Halted 0 ms 0 KB -