社区讨论

0pts求助

P5663[CSP-J 2019] 加工零件参与者 4已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@lo187kn9
此快照首次捕获于
2023/10/22 16:47
2 年前
此快照最后确认于
2023/11/02 16:37
2 年前
查看原帖
rt,从35pts跌到了0pts
CPP
#include <map>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
class edge{
    public:
        int to_node,next_edge;
        edge(){
            this->to_node=this->next_edge=-1;
        }
};
int n,m,q,l,head[114514],u,v,kkk,dista[114514],distb[114514],now,cache,line;
edge edges[1919810];
queue < pair < int , int > > qq;
void push_edge(){
    edges[kkk].next_edge=head[u],edges[kkk].to_node=v,head[u]=kkk,++kkk;
    edges[kkk].next_edge=head[v],edges[kkk].to_node=u,head[v]=kkk,++kkk;
}
void bfs(){
    now=0,dista[0]=0;
    qq.push({0,now});
    while(!qq.empty()){
        now=qq.front().second,line=qq.front().first,qq.pop();
//        printf("%d ",now);
        for(int i=head[now];i>=0;i=edges[i].next_edge){
//        	printf("%d ",i);
            cache=edges[i].to_node;
            if(!(line&1)&&dista[now]+1<distb[cache]){
				distb[cache]=dista[now]+1;
            	qq.push({distb[cache],cache});
			}
            if((line&1)&&distb[now]+1<dista[cache]){
				dista[cache]=distb[now]+1;
            	qq.push({dista[cache],cache});
			}
		}
    }
}
int main(){
	memset(head,-1,sizeof(head));
    memset(dista,0x7f,sizeof(dista));
    memset(distb,0x7f,sizeof(distb));
    freopen("P5663 [CSP-J2019] 加工零件.in","r",stdin);
    freopen("P5663 [CSP-J2019] 加工零件.out","w",stdout);
	scanf("%d%d%d",&n,&m,&q);
    for(int i=0;i<m;++i){
        scanf("%d%d",&u,&v);
        --u,--v;
        push_edge();
    }
    bfs();
    for(int i=0;i<q;++i){
        scanf("%d%d",&u,&l);
        --u;
        if(l&1){
        	if(l>=dista[u])printf("Yes\n");
        	else printf("No\n");
        }else{
        	if(l>=distb[u])printf("Yes\n");
        	else printf("No\n");
        }
    }
    return 0;
}

回复

3 条回复,欢迎继续交流。

正在加载回复...