zoukankan      html  css  js  c++  java
  • CodeForces 707B Bakery

    枚举。

    枚举每一条边,如果发现边的一端$f[u]=1$,另一端$f[v]=0$,那么更新答案,取最小值就好了。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-6;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    template <class T>
    inline void read(T &x)
    {
        char c = getchar(); x = 0;while(!isdigit(c)) c = getchar();
        while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar();  }
    }
    
    const int INF=0x7FFFFFFF;
    const int maxn=100010;
    int n,m,k;
    bool f[maxn];
    struct X{int u,v,w;}s[maxn];
    
    int main()
    {
        scanf("%d%d%d",&n,&m,&k);
        for(int i=1;i<=m;i++) scanf("%d%d%d",&s[i].u,&s[i].v,&s[i].w);
        for(int i=1;i<=k;i++)
        {
            int x; scanf("%d",&x);
            f[x]=1;
        }
        int ans=INF;
        for(int i=1;i<=m;i++)
        {
            if(f[s[i].u]&&f[s[i].v]) continue;
            if(!f[s[i].u]&&!f[s[i].v]) continue;
            ans=min(ans,s[i].w);
        }
        if(ans==INF) printf("-1
    ");
        else printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    cf D. Vessels
    cf C. Hamburgers
    zoj 3758 Singles' Day
    zoj 3777 Problem Arrangement
    zoj 3778 Talented Chef
    hdu 5087 Revenge of LIS II
    zoj 3785 What day is that day?
    zoj 3787 Access System
    判断给定图是否存在合法拓扑排序
    树-堆结构练习——合并果子之哈夫曼树
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5836314.html
Copyright © 2011-2022 走看看