Codeforce 893C Rumor (dfs)
来源:互联网 发布:战斗妖精雪风小说淘宝 编辑:程序博客网 时间:2024/06/05 15:19
you can find the problem in this link
given you N nodes and M edge , find the smallest number in each connect block and sum them up;
well , this is a simple dfs and I think I should use some data structure like union set but use vector to storage the edges and the time complexity is promising .
#include <bits/stdc++.h>#include <cstring>#define ll long long#define in :using namespace std;vector<int> edge[100001];int c[100001],vis[1000001];int n,m;void addedge(int u,int v){ edge[u].push_back(v); edge[v].push_back(u);}int dfs(int st){ int ans = c[st]; for(auto i in edge[st]) { if(vis[i]) continue; vis[i] = 1; ans = min(ans,dfs(i)); } return ans;}int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n>>m; for(int i = 1;i<=n;i++) { cin>>c[i]; } int u,v; for(int i = 0;i<m;i++) { cin>>u>>v; addedge(u,v); } ll ans = 0; memset(vis,0,sizeof(vis)); for(int i = 1;i<=n;i++) { if(!vis[i]) vis[i] = 1,ans += (ll)dfs(i); } cout<<ans<<endl; return 0;}
the mistake I made is make the question more complex and forget to left the mark. It should be think carefully.
阅读全文
0 0
- Codeforce 893C Rumor (dfs)
- CodeForces 893C Rumor
- codeforces 893 C.Rumor
- *【codeforce】782C 【dfs】
- CF C. Rumor
- codeforce C. Valera and Elections (DFS)
- CodeForce 505C Mr. Kitayuta(DP+DFS)
- codeforce 550c Divisibility by Eight (DFS)
- Codeforce 839C Journey (dfs+概率)
- Educational Codeforces Round 33 C. Rumor
- codeforce 6B dfs
- codeforce New Problem(dfs)
- DFS&&codeforce 598d
- 【Educational Codeforces Round 33】 C. Rumor (并查集)
- codeforce 659E (dfs 水~)
- codeforce 842C. Ilya And The Tree(dfs用set存储到每种可能)
- Codeforce # C. Average Score
- CodeForce 279C
- PHP 分页(limit)
- 安装oracle出现Could not execute auto check for display colors using command
- 文章标题
- cuda优化
- Nginx配置官方yum源报404
- Codeforce 893C Rumor (dfs)
- WebWorker 工作线程
- samba源码安装
- 一元运算符重载
- Android自定义控件下拉刷新实例代码
- NodeMCU--学习笔记(二)GPIO操作
- 【死磕Java并发】-----分析 ArrayBlockingQueue 构造函数加锁问题
- 动脑学院课程视频性能优化,移动框架,高级UI,DNK
- 数据结构------栈和队列