이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |