• 【最小生成树】Codeforces 707B Bakery


    题目链接:

      http://codeforces.com/problemset/problem/707/B

    题目大意:

      给你N个点M条无向边,其中有K个面粉站,现在一个人要在不是面粉站的点上开店,问到面粉站的最短距离是多少。无法开店输出-1.

    题目思路:

      【最小生成树】

      把边长按距离从小到大排序,出现的第一个只含一个面粉店的边为所求。

      

     1 //
     2 //by coolxxx
     3 //#include<bits/stdc++.h>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<map>
     9 #include<memory.h>
    10 #include<time.h>
    11 #include<stdio.h>
    12 #include<stdlib.h>
    13 #include<string.h>
    14 //#include<stdbool.h>
    15 #include<math.h>
    16 #define min(a,b) ((a)<(b)?(a):(b))
    17 #define max(a,b) ((a)>(b)?(a):(b))
    18 #define abs(a) ((a)>0?(a):(-(a)))
    19 #define lowbit(a) (a&(-a))
    20 #define sqr(a) ((a)*(a))
    21 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    22 #define mem(a,b) memset(a,b,sizeof(a))
    23 #define eps (1e-8)
    24 #define J 10
    25 #define mod 1000000007
    26 #define MAX 0x7f7f7f7f
    27 #define PI 3.14159265358979323
    28 #define N 100004
    29 using namespace std;
    30 typedef long long LL;
    31 int cas,cass;
    32 int n,m,lll,ans;
    33 struct xxx
    34 {
    35     int b,e,d;
    36 }a[N];
    37 bool mark[N];
    38 bool cmp(xxx aa,xxx bb)
    39 {
    40     return aa.d<bb.d;
    41 }
    42 int main()
    43 {
    44     #ifndef ONLINE_JUDGE
    45 //    freopen("1.txt","r",stdin);
    46 //    freopen("2.txt","w",stdout);
    47     #endif
    48     int i,j,k;
    49     int x,y,z;
    50 //    for(scanf("%d",&cas);cas;cas--)
    51 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    52 //    while(~scanf("%s",s+1))
    53     while(~scanf("%d",&n))
    54     {
    55         mem(mark,0);
    56         scanf("%d%d",&m,&k);
    57         for(i=1;i<=m;i++)
    58             scanf("%d%d%d",&a[i].b,&a[i].e,&a[i].d);
    59         sort(a+1,a+1+m,cmp);
    60         for(i=1;i<=k;i++)
    61         {
    62             scanf("%d",&x);
    63             mark[x]=1;
    64         }
    65         for(i=1;i<=m;i++)
    66             if(mark[a[i].b]+mark[a[i].e]==1)break;
    67         if(i>m)puts("-1");
    68         else printf("%d
    ",a[i].d);
    69     }
    70     return 0;
    71 }
    72 /*
    73 //
    74 
    75 //
    76 */
    View Code
     
  • 相关阅读:
    XBee Level Shifting
    5V and 3V Level Translators
    Short Circuit Protection Circuit
    Non-Inverting Level Shifter : +/-5V signal into a 0 to 3.3V
    7407 74LS07 74LV07 74LVC07
    xvcd – The Xilinx Virtual Cable Daemon
    74HC125 74HCT125 74LV125 74LVC125
    SQL Server全文搜索
    分享今天在客户那里遇到的SQLSERVER连接超时以及我的解决办法
    关于《SQLSERVER走起》微信账号自动回复功能的升级
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5792294.html
Copyright © 2020-2023  润新知