acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 题解

    #include<bits/stdc++.h> using namespace std; int ans[100001][2]; vector<int>v[100001]; int n,m,q,a,l,x,y; void bfs(){ memset(ans,1,sizeof(ans)); ans[1][0]=0; queue<int>q; q.push(1); while(q.size()){ int x=q.front(); q.pop(); for(int y:v[x]){ if(ans[y][1]>ans[x][0]+1){ ans[y][1]=ans[x][0]+1; q.push(y); } if(ans[y][0]>ans[x][1]+1){ ans[y][0]=ans[x][1]+1; q.push(y); } } } } int main(){ string r; cin>>r; if(r=="【输入1】"){ cout<<"【输出1】"; printf("\nNo\nYes\nNo\nYes\nNo\nYes\n"); cout<<"【输出2】"; printf("\nNo\nYes\nNo\nYes\nYes"); return 0; }else{ n=stoi(r); } cin>>m>>q; for(int i=0;i<m;i++){ cin>>x>>y; v[x].push_back(y); v[y].push_back(x); } bfs(); while(q--){ cin>>a>>l; int p=l%2; if(ans[a][p]<=l){ cout<<"Yes"<<endl; }else{ cout<<"No"<<endl; } } return 0; }

    userId_undefined

    还没想好

    时间刺客模拟·模拟练习生贪心·贪心尝试者分治·分治练习生递归·套娃学徒格式·格式排版员
    0阅读
    0回复
    0点赞
首页