| 比赛 |
NOIP2025模拟赛1 |
评测结果 |
WWWWWWWAWW |
| 题目名称 |
路径覆盖 |
最终得分 |
10 |
| 用户昵称 |
wdsjl |
运行时间 |
0.199 s |
| 代码语言 |
C++ |
内存使用 |
4.85 MiB |
| 提交时间 |
2025-11-24 11:05:27 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
struct node{
int fr,to,nxt;
}e[N*2];
int hd[N],cnt;
int n,q;
int d[N],maxx,res[N];
int main(){
freopen("lucover.in","r",stdin);
freopen("lucover.out","w",stdout);
scanf("%d%d",&n,&q);
for(int i=1;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
e[++cnt]={x,y,hd[x]};
hd[x]=cnt;
e[++cnt]={y,x,hd[y]};
hd[y]=cnt;
d[x]++;
d[y]++;
maxx=max({maxx,d[x],d[y]});
}
if(maxx==2){
for(int i=1;i<=n;i++){
if(d[i]==1){
res[i]=2;
res[e[hd[i]].to]=2;
}
}
for(int i=1;i<=n;i++){
if(res[i]==0)res[i]=3;
}
while(q--){
int x;
scanf("%d",&x);
printf("%d\n",res[x]);
}
}else{
while(q--){
int x;
scanf("%d",&x);
if(d[x]==1){
printf("%d\n",n-2);
}else{
printf("%d\n",1);
}
}
}
return 0;
}