QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#617015 | #1955. Double Rainbow | AnotherDayofSun# | WA | 2ms | 11924kb | C++14 | 1.6kb | 2024-10-06 13:30:22 | 2024-10-06 13:30:23 |
Judging History
answer
#include<bits/stdc++.h>
#define re
#define N 300005
#define ll long long
using namespace std;
int n,m,K,q,T;
inline void Rd(int &res){
re char c;res=0;
while(c=getchar(),c<48);
do res=(res<<3)+(res<<1)+(c^48);
while(c=getchar(),c>47);
}
int head[N],to[N<<1],nxt[N<<1],cnt1;
inline void adde(int x,int y){to[++cnt1]=y;nxt[cnt1]=head[x];head[x]=cnt1;}
int fak[N],fa[N],dep[N],stk[N],top;
void dfs(int x,int f){
fa[x]=f;
stk[++top]=x;
if(top>K)fak[x]=stk[top-K];
else fak[x]=stk[1];
dep[x]=dep[f]+1;
for(int i=head[x];i;i=nxt[i]){
int y=to[i];
if(y==f)continue;
dfs(y,x);
}
}
struct node{
int x,d;
}A[N];
bool cmp(node a,node b){return a.d>b.d;}
bool mk[N],ts[N],now[N];
int Q[N],D[N];
void bfs(int st){
ts[st]=1;
int l=0,r=0;
Q[++r]=st;D[r]=0;
while(l<r){
int x=Q[++l];
int d=D[l];
if(l!=1&&ts[x])continue;
now[x]=1;mk[st]=1;
if(d==K)continue;
for(int i=head[x];i;i=nxt[i]){
int y=to[i];
if(now[y])continue;
Q[++r]=y;D[y]=d+1;
}
}
for(int i=1;i<=r;i++)now[Q[i]]=0;
}
int main(){
Rd(n),Rd(K);
for(int i=1;i<n;i++){
int x,y;
Rd(x),Rd(y);
adde(x,y);
adde(y,x);
}
dfs(1,0);
for(int i=1;i<=n;i++)A[i]=(node){i,dep[i]};
sort(A+1,A+n+1,cmp);
int ans=0;
for(int i=1;i<=n;i++){
int x=A[i].x;
if(mk[x])continue;
printf("mark: %d\n",fak[x]);
bfs(fak[x]);
ans++;
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 11924kb
input:
1 1 1
output:
mark: 1 1
result:
wrong answer 1st lines differ - expected: '0', found: 'mark: 1'