답안 #505091

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
505091 2022-01-10T13:19:14 Z tgbegimx Dynamite (POI11_dyn) C++14
컴파일 오류
0 ms 0 KB
1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int N=300005,inf=0x3f3f3f3f;
 6 int p[N],noww[2*N],goal[2*N];
 7 int imp[N],unc[N],cov[N];
 8 int n,m,t1,t2,cnt,tot,l,r,mid,ans;
 9 void link(int f,int t)
10 {
11     noww[++cnt]=p[f];
12     goal[cnt]=t,p[f]=cnt;
13 }
14 void DFS(int nde,int fth)
15 {
16     unc[nde]=-inf,cov[nde]=inf;
17     for(int i=p[nde];i;i=noww[i])    
18         if(goal[i]!=fth)
19         {
20             DFS(goal[i],nde);
21             unc[nde]=max(unc[nde],unc[goal[i]]+1);
22             cov[nde]=min(cov[nde],cov[goal[i]]+1);
23         }
24     if(imp[nde]&&cov[nde]>mid) unc[nde]=max(unc[nde],0);
25     if(unc[nde]+cov[nde]<=mid) unc[nde]=-inf;
26     if(unc[nde]==mid) unc[nde]=-inf,cov[nde]=0,tot++;
27 }
28 bool check(int x)
29 {
30     tot=0; DFS(1,0);
31     return tot+(unc[1]>=0)<=m;
32 }
33 int main ()
34 {
35     scanf("%d%d",&n,&m),r=n;
36     for(int i=1;i<=n;i++) 
37         scanf("%d",&imp[i]);
38     for(int i=1;i<n;i++)
39     {
40         scanf("%d%d",&t1,&t2);
41         link(t1,t2),link(t2,t1);
42     }
43     while(l<=r)
44     {
45         mid=(l+r)/2;
46         if(check(mid)) r=mid-1,ans=mid; 
47         else l=mid+1;
48     }
49     printf("%d",ans);
50     return 0;
51 }
 View Code

Compilation message

dyn.cpp:1:3: error: stray '#' in program
    1 | 1 #include<cstdio>
      |   ^
dyn.cpp:2:4: error: stray '#' in program
    2 |  2 #include<cstring>
      |    ^
dyn.cpp:3:4: error: stray '#' in program
    3 |  3 #include<algorithm>
      |    ^
dyn.cpp:1:1: error: expected unqualified-id before numeric constant
    1 | 1 #include<cstdio>
      | ^
dyn.cpp:5:2: error: expected unqualified-id before numeric constant
    5 |  5 const int N=300005,inf=0x3f3f3f3f;
      |  ^
dyn.cpp:6:2: error: expected unqualified-id before numeric constant
    6 |  6 int p[N],noww[2*N],goal[2*N];
      |  ^
dyn.cpp:7:2: error: expected unqualified-id before numeric constant
    7 |  7 int imp[N],unc[N],cov[N];
      |  ^
dyn.cpp:8:2: error: expected unqualified-id before numeric constant
    8 |  8 int n,m,t1,t2,cnt,tot,l,r,mid,ans;
      |  ^
dyn.cpp:9:2: error: expected unqualified-id before numeric constant
    9 |  9 void link(int f,int t)
      |  ^
dyn.cpp:14:1: error: expected unqualified-id before numeric constant
   14 | 14 void DFS(int nde,int fth)
      | ^~
dyn.cpp:28:1: error: expected unqualified-id before numeric constant
   28 | 28 bool check(int x)
      | ^~
dyn.cpp:33:1: error: expected unqualified-id before numeric constant
   33 | 33 int main ()
      | ^~
dyn.cpp:52:2: error: 'View' does not name a type
   52 |  View Code
      |  ^~~~