Submission #505093

# Submission time Handle Problem Language Result Execution time Memory
505093 2022-01-10T13:21:15 Z tgbegimx Dynamite (POI11_dyn) C++14
100 / 100
1081 ms 20600 KB
#include<cstdio>
  #include<cstring>
  #include<algorithm>
  using namespace std;
  const int N=300005,inf=0x3f3f3f3f;
  int p[N],noww[2*N],goal[2*N];
  int imp[N],unc[N],cov[N];
  int n,m,t1,t2,cnt,tot,l,r,mid,ans;
  void link(int f,int t)
 {
     noww[++cnt]=p[f];
     goal[cnt]=t,p[f]=cnt;
 }
 void DFS(int nde,int fth)
  {
     unc[nde]=-inf,cov[nde]=inf;
     for(int i=p[nde];i;i=noww[i])
        if(goal[i]!=fth)
         {

             DFS(goal[i],nde);
             unc[nde]=max(unc[nde],unc[goal[i]]+1);
             cov[nde]=min(cov[nde],cov[goal[i]]+1);
         }
        if(imp[nde]&&cov[nde]>mid) unc[nde]=max(unc[nde],0);
     if(unc[nde]+cov[nde]<=mid) unc[nde]=-inf;
     if(unc[nde]==mid) unc[nde]=-inf,cov[nde]=0,tot++;
 }
 bool check(int x)
 {
     tot=0; DFS(1,0);
     return tot+(unc[1]>=0)<=m;
 }
 int main ()
 {
     scanf("%d%d",&n,&m),r=n;
     for(int i=1;i<=n;i++)
         scanf("%d",&imp[i]);
     for(int i=1;i<n;i++)
     {
         scanf("%d%d",&t1,&t2);
         link(t1,t2),link(t2,t1);
     }
     while(l<=r)
     {
         mid=(l+r)/2;
         if(check(mid)) r=mid-1,ans=mid;
         else l=mid+1;
     }
     printf("%d",ans);
     return 0;
 }

Compilation message

dyn.cpp: In function 'void DFS(int, int)':
dyn.cpp:17:6: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   17 |      for(int i=p[nde];i;i=noww[i])
      |      ^~~
dyn.cpp:25:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   25 |         if(imp[nde]&&cov[nde]>mid) unc[nde]=max(unc[nde],0);
      |         ^~
dyn.cpp: In function 'int main()':
dyn.cpp:36:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |      scanf("%d%d",&n,&m),r=n;
      |      ~~~~~^~~~~~~~~~~~~~
dyn.cpp:38:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |          scanf("%d",&imp[i]);
      |          ~~~~~^~~~~~~~~~~~~~
dyn.cpp:41:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |          scanf("%d%d",&t1,&t2);
      |          ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 588 KB Output is correct
2 Correct 20 ms 972 KB Output is correct
3 Correct 23 ms 1224 KB Output is correct
4 Correct 28 ms 2980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 1792 KB Output is correct
2 Correct 79 ms 2380 KB Output is correct
3 Correct 98 ms 2792 KB Output is correct
4 Correct 84 ms 5688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 3296 KB Output is correct
2 Correct 106 ms 3408 KB Output is correct
3 Correct 166 ms 3420 KB Output is correct
4 Correct 132 ms 8368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 410 ms 6632 KB Output is correct
2 Correct 394 ms 7492 KB Output is correct
3 Correct 807 ms 15648 KB Output is correct
4 Correct 762 ms 15560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 972 ms 12192 KB Output is correct
2 Correct 741 ms 9648 KB Output is correct
3 Correct 1081 ms 14892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 935 ms 18584 KB Output is correct
2 Correct 813 ms 9644 KB Output is correct
3 Correct 992 ms 20600 KB Output is correct
4 Correct 204 ms 9824 KB Output is correct