zoukankan      html  css  js  c++  java
  • 【Educational Codeforces Round 33 C】 Rumor

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    显然最后会形成多个集合,每个集合里面的人能够可以互相到达。 则维护并查集的时候,顺便维护一下每个集合里面的最小值就好。 最后答案就为∑min{每个集合}

    【代码】

    /*
      	1.Shoud it use long long ?
      	2.Have you ever test several sample(at least therr) yourself?
      	3.Can you promise that the solution is right? At least,the main ideal
      	4.use the puts("") or putchar() or printf and such things?
      	5.init the used array or any value?
      	6.use error MAX_VALUE?
      	7.use scanf instead of cin/cout?
    */
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 1e5;
    
    int f[N+10],mi[N+10],n,m;
    bool bo[N+10];
    
    int ff(int x){
    	if (f[x]==x) return x;
    	else return f[x] = ff(f[x]);
    }
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("F:\c++source\rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
    	cin >> n >> m;
    	for (int i = 1;i <= n;i++){
    		cin >> mi[i];
    		f[i] = i;
    	}
    	for (int i = 1;i <= m;i++){
    	 	int x,y;
    	 	cin >> x >> y;
    	    int r1 = ff(x),r2 = ff(y);
    	    if (r1!=r2){
    	     	f[r1] = r2;
    	     	mi[r2] = min(mi[r2],mi[r1]);
    		}
    	}
    
    	long long ans = 0;
    	for (int i = 1;i <= n;i++){
    	 	int x = ff(i);
    	 	if (!bo[x]){
    	 	 	bo[x] = true;
    	 	 	ans += mi[x];
    	 	}
    	}
    
    	cout << ans << endl;
    
    	return 0;
    }	
    
  • 相关阅读:
    pyecharts包学习笔记
    敏捷测试关键成功因素
    JMeter—常见问题(十四)
    性能测试面试题
    python-Tkinter整理总结
    JMeter—系统性能分析思路(十三)
    JMeter—监听器(十二)
    JMeter—断言(十一)
    yii2.0 的数据的 增
    Windows下安装 使用coreseek
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7888316.html
Copyright © 2011-2022 走看看