zoukankan      html  css  js  c++  java
  • CF1184E1

    题目大意:

    给出(n)个点(m)条边的无向图,你可以修改第一条边的权值,使得他可能会处于一棵最小生成树中,问你第一条的权值最大(不超过1e9)可以改为多少。

    这个题我们不去使用第一条边去跑最小生成树,然后在跑的过程中,有一条边连接的两个联通分量与第一条连接是一样的,那么答案就是这条边的权值

    如果最后没办法联通,说明第一条边是割边,答案是1e9。

    #define B cout << "BreakPoint" << endl;
    #define O(x) cout << #x << " " << x << endl;
    #define O_(x) cout << #x << " " << x << " ";
    #define Msz(x) cout << "Sizeof " << #x << " " << sizeof(x)/1024/1024 << " MB" << endl;
    #include<cstdio>
    #include<cmath>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<set>
    #define fi first
    #define se second
    #define LL long long
    const int inf = 1e9 + 9;
    const int N = 2e6 + 5;
    using namespace std;
    inline int read() {
    	int s = 0,w = 1;
    	char ch = getchar();
    	while(ch < '0' || ch > '9') {
    		if(ch == '-')
    			w = -1;
    		ch = getchar();
    	}
    	while(ch >= '0' && ch <= '9') {
    		s = s * 10 + ch - '0';
    		ch = getchar();
    	}
    	return s * w;
    }
    int fa[N];
    int find(int x){
        return x == fa[x] ? x : fa[x] = find(fa[x]);
    }
    vector<pair<int,pair<int,int> > > e(N);
    int main(){
        int n = read(),m = read();
        for(int i = 0;i < m;i++){
            e[i].se.fi = read();
    		e[i].se.se = read();
    		e[i].fi = read();
        }  
        sort(e.begin() + 1,e.end());
        for(int i = 1;i <= n + 5;i++) fa[i] = i;
        for(int i = 1;i < e.size();i++){
            int u = find(e[i].se.fi),v = find(e[i].se.se);
            if(u != v){
                int x = find(e[0].se.fi),y = find(e[0].se.se);
                if(x == u && y == v) printf("%d
    ",e[i].fi),exit(0);
                if(x == v && y == u) printf("%d
    ",e[i].fi),exit(0);
                fa[u] = v;
            }
        }
        printf("%d
    ",(int)1e9);
    }
    
  • 相关阅读:
    XSLT的Replace函数
    Predicate<T> 委托
    《人生的智慧》第二章 人的自身
    Kmeans文本聚类:获取weka计算的聚类中心,完成文本聚类
    VCKbase转载:C++调用ADO
    Kmeans文本聚类系列之如何调用Preprocess类
    Kmeans文本聚类系列之全部代码
    近期计划
    Kmeans 聚类之建立文档向量模型(VSM)
    LibSVM文本分类之结果统计
  • 原文地址:https://www.cnblogs.com/excellent-zzy/p/12548345.html
Copyright © 2011-2022 走看看