Submission #338419

#TimeUsernameProblemLanguageResultExecution timeMemory
338419beksultan04Biochips (IZhO12_biochips)C++14
0 / 100
33 ms47488 KiB
#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)

biochips.cpp: In function 'void rec(long long int)':
biochips.cpp:25:15: 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]
   25 |     for (i=0;i<gg[x].size();++i){
      |              ~^~~~~~~~~~~~~
biochips.cpp: In function 'void dfs(long long int, long long int, long long int)':
biochips.cpp:43:15: 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]
   43 |     for (i=0;i<g[x].size();++i){
      |              ~^~~~~~~~~~~~
biochips.cpp: At global scope:
biochips.cpp:49:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main(){
      |      ^
biochips.cpp: In function 'int main()':
biochips.cpp:50:15: warning: unused variable 'cnt' [-Wunused-variable]
   50 |     int i,j,s,cnt=1;
      |               ^~~
biochips.cpp:12:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
biochips.cpp:51:5: note: in expansion of macro 'scan2'
   51 |     scan2(n,m)
      |     ^~~~~
biochips.cpp:12:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
biochips.cpp:54:9: note: in expansion of macro 'scan2'
   54 |         scan2(x,ves[i])
      |         ^~~~~
biochips.cpp:60:8: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |     rec(s);
      |     ~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...