POJ2263

 //#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define per(i,r,l) for(int i=(r);i>=(l);i--)
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define debug1(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << endl;\
cout << #b << " = " << b << endl;
#define debug3(a,b,c) cout << #a << " = " << a << endl;\
cout << #b << " = " << b << endl;\
cout << #c << " = " << c << endl;
#define debug4(a,b,c,d)\
cout << #a << " = " << a << endl;\
cout << #b << " = " << b << endl;\
cout << #c << " = " << c << endl;\
cout << #d << " = " << d << endl;
#define eps 1e-9
#define PIE acos(-1)
#define cl(a,b) memset(a,b,sizeof(a))
#define fastio ios::sync_with_stdio(false);cin.tie(0);
#define lson l , mid , ls
#define rson mid + 1 , r , rs
#define ls (rt<<1)
#define rs (ls|1)
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
#define sqr(a) a*a
#pragma GCC optimize(2)
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii; const int maxn=2e5;
int u[maxn],v[maxn],w[maxn],p[maxn],r[maxn];
int n,m,cnt;
map<string,int>MAP; int cmp(const int i,const int j){return w[i]>w[j];}
int find(int x){return p[x]==x?x:p[x]=find(p[x]);}
int kruscal(int t1,int t2)
{
int ans=;
rep(i,,maxn)p[i]=r[i]=i;
sort(r,r+m,cmp);
rep(i,,m){
int e=r[i];
int x=find(u[e]);
int y=find(v[e]);
if(x!=y){
p[x]=y;
if(find(t1)==find(t2)){
ans=w[e];
return ans;
}
}
}
return w[r[m]];
}
void Init()
{
MAP.clear();
cnt=;
}
int main()
{
int cas=;
while(cin>>n>>m,n&&m){
Init();
char s1[],s2[];
rep(i,,m){
scanf("%s%s%d",s1,s2,&w[i]);
if(!MAP.count(s1))MAP[s1]=cnt++;
if(!MAP.count(s2))MAP[s2]=cnt++;
u[i]=MAP[s1];
v[i]=MAP[s2];
// debug3(MAP[s1],MAP[s2],w[i]);
}
scanf("%s%s",s1,s2);
printf("Scenario #%d\n", ++cas);
printf("%d tons\n\n", kruscal(MAP[s1],MAP[s2]));
// printf("Scenario #%d\n%d tons\n\n",++cas,kruscal(MAP[s1],MAP[s2]));
}
return ;
}

最大生成树+map实现技巧的更多相关文章

  1. map,实现技巧,id

    cf #include<iostream> #include<cstdio> #include<algorithm> #include<vector> ...

  2. 总结golang之map

    总结golang之map 2017年04月13日 23:35:53 趁年轻造起来 阅读数:18637 标签: golangmapgo 更多 个人分类: golang   版权声明:本文为博主原创文章, ...

  3. Go语言语法说明

    Go语言语法说明 go语言中的go func(){}() 表示以并发的方式调用匿名函数func 深入讲解Go语言中函数new与make的使用和区别 前言 本文主要给大家介绍了Go语言中函数new与ma ...

  4. 用golang开发系统软件的一些细节

    用golang开发系统软件的一些细节 作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 (本文的pdf版本) ...

  5. 调试技巧 —— 如何利用windbg + dump + map分析程序异常

    调试技巧 —— 如何利用windbg + dump + map分析程序异常 逗比汪星人2011-09-04上传   调试技巧 —— 如何利用windbg + dump + map分析程序异常 http ...

  6. 【转】Java学习---Java核心数据结构(List,Map,Set)使用技巧与优化

    [原文]https://www.toutiao.com/i6594587397101453827/ Java核心数据结构(List,Map,Set)使用技巧与优化 JDK提供了一组主要的数据结构实现, ...

  7. poj 3320 技巧/尺取法 map标记

    Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...

  8. C++STL中map容器的说明和使用技巧(杂谈)

    1.map简介 map是一类关联式容器.它的特点是增加和删除节点对迭代器的影响很小,除了那个操作节点,对其他的节点都没有什么影响.对于迭代器来说,可以修改实值,而不能修改key. 2.map的功能 自 ...

  9. Java核心数据结构(List,Map,Set)原理与使用技巧

    JDK提供了一组主要的数据结构实现,如List.Map.Set等常用数据结构.这些数据都继承自 java.util.Collection 接口,并位于 java.util 包内. 1.List接口 最 ...

随机推荐

  1. Java Web-EL表达式 in JSP

    Java Web-EL表达式 in JSP 概念 EL(Expression Language)是一种表达式语言,可以替换和简化JSP页面上JAVA代码的书写 语法 ${<在这里写表达式> ...

  2. canvas学习之初级运用

    <html> <head> <meta charset=utf-8> <title>绘制简单图形</title> <style typ ...

  3. java实现判定新旧版本号

    废话不多说,直接上代码 /** * 判断是否为最新版本方法 将版本号根据.切分为int数组 比较 * * @param localVersion 本地版本号 * @param onlineVersio ...

  4. CentOS下安装好python和opencv,却import cv2失败

    在安装好CentOS和OpenCV后,在终端输入python,在输入import cv2.却报错:ImportError:Mo module named cv2.浏览Python下文件夹发现cv2.s ...

  5. linux下搭建redis内网端口映射工具-rinetd

    最近在工作中使用到了redis缓存,用来提某些业务场景的计算速度和某些情况下的操作频率限制,客户端工具使用了redisDesktopmanager来管理,在本机操作测试的时候,是没有问题的.但是将系统 ...

  6. TensorFlow 拾遗

     1..Here None in placeholder means that a dimension can be of any length.   2..   3.. 4.. 5.. tf.mul ...

  7. Word2Vec详解

    Word2Vec详解 word2vec可以在百万数量级的词典和上亿的数据集上进行高效地训练:其次,该工具得到的训练结果--词向量(word embedding),可以很好地度量词与词之间的相似性.随着 ...

  8. 类的命名空间与卸载详解及jvisualvm使用

    类的命名空间详解: 在上一次[https://www.cnblogs.com/webor2006/p/9108301.html]最后实验中有一个违背咱们理解的,这里回顾一下: 也就是说,"某 ...

  9. java中的集合总结

    知识点: 集合框架和List.set.Map相关集合特点的描述 Collection接口常用方法,List中相对Collection新增的方法,Collection的遍历(一般for循环,增强for循 ...

  10. linux异步传输支持

    基于libusbx-1.0.18-rc1,libusbx现已重新merage到libusb.1. 初始化使用libusb_init初始化libusb,如果是单设备通信,ctx参数可以传NULL,表示使 ...