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

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情提交记录(0)
  • 广搜(其实也可以用换根DP)

    #include<iostream> #include<queue> #include<vector> #include<cstring> using namespace std; const int maxn = 2e5 + 15,tnt = 0x3f3f3f3f; int n,stamp; vector<int> vis; vector<vector<int>> mp; void bfs(int s){ vector<int> d(n + 5,tnt); queue<int> q; stamp++; q.push(s); d[s] = 0; vis[s] = stamp; while(!q.empty()){ int r = q.front(); q.pop(); for(auto next : mp[r]){ if(vis[next] != stamp){ q.push({next}); vis[next] = stamp; d[next] = d[r] + 1; } } } int ans = 0; for(int i = 1;i <= n;i++){ if(d[i] % 2 == 0 && d[i] != tnt) ans++; } cout << ans << " "; } int main(){ cin >> n; mp.resize(n + 5),vis.resize(n + 5,0); for(int i = 1;i < n;i++){ int x,y; cin >> x >> y; mp[x].push_back(y); mp[y].push_back(x); } for(int i = 1;i <= n;i++){ bfs(i); } }

    userId_undefined

    137****0822

    9月全勤卷王秩序白银时间刺客空间掌握者时空双修者快乐小狗
    2阅读
    0回复
    0点赞
暂无数据

提交答案之后,这里将显示提交结果~

首页