Submission #525078

# Submission time Handle Problem Language Result Execution time Memory
525078 2022-02-10T16:02:49 Z ammar2000 Magic Tree (CEOI19_magictree) C++17
0 / 100
2000 ms 5960 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
#define coy cout<<"YES\n"
#define con cout<<"NO\n"
#define co1 cout<<"-1\n"
#define sc(x) scanf("%lld",&x)
#define all(x) x.begin(),x.end()
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int SI=3e5+7;
ll INF=8e18+7;
int dx[] = {1 , -1 , 0 , 0};
int dy[] = {0 , 0 , 1 , -1};
int MOD=1e9+7;
vector <ll> bin;
ll n,m,k,p[SI],r[SI],f[SI],t[SI];
bool UP(int node)
{
    ll small=r[node];
    while (node!=1)
    {
        if (t[node]==1&&r[node]<small)
            return 0;
    /*    if (t[node])
        cout << r[node]<<" "<<small <<"\n";
      */  node=p[node];
   //     cout  << node<<"\n";
    }
    return 1;
}
int main()
{
   fast
   cin>>n>>m>>k;
   swap (m,k);
   for (int i=2;i<=n;i++)
      cin>>p[i];
   for (int i=0;i<k;i++)
   {
       ll a,b,c;
       cin>>a>>b>>c;
       r[a]=b;
       f[i]=a;
   }
  // for (int i=0;i<k;i++)\
    cout << f[i]<<" ";
   ll e=(1<<k)-1;
   vector <ll> v;
   ll ans=0;
   for (int i=1;i<=e;i++)
   {
       v.clear();
       for (int i=1;i<=n;i++)
        t[i]=0;
       for (int o=0;o<k;o++)
       {
           if (i&(1<<o))
            v.pb(o),t[o]=1;
       }
       bool fl=1;
       for (auto y:v)
       {
           bool is=UP(f[y]);
           fl&=is;
       }
       if (fl&&ans<v.size())
        ans=v.size();
   }
   cout << ans <<"\n";
   // use scanf not cin
   return 0;
}

Compilation message

magictree.cpp:48:3: warning: multi-line comment [-Wcomment]
   48 |   // for (int i=0;i<k;i++)\
      |   ^
magictree.cpp: In function 'int main()':
magictree.cpp:69:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |        if (fl&&ans<v.size())
      |                ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Incorrect 83 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 4056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2073 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2072 ms 5960 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Incorrect 83 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Incorrect 83 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Incorrect 83 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -