hoj 13792 Model Railroad

// 想了半天才发现是道生成树 然后想了好久 出了好多数据都他吗过了 但是a不了 后来发现给定数据 有的就不能构成一棵树 这点没有特判 如果我代码写的好一些 吧生成树写成函数 就他妈规避了这个问题草#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <vector>
#include <map>
#include <math.h>
#define LL long long
#define INF 2100000000
#define fi first
#define se second
#define PI 3.1415927
#define lowbit(x) (x&(-x))
using namespace std;
const int maxn=(int)5e4 +30;
const int MOD=(int)1e9+7;

template<class T>inline void MAX(T &a,T b)
{
    if(a<b)a=b;
}
template<class T>inline void MIN(T &a,T b)
{
    if(a>b)a=b;
}
struct nod
{
    int x,y,val;
    bool f;
    // nod(int x,int y,int val,int f):x(x),y(y),val(val),f(f){}
    bool operator <(const nod&a )const
    {
        return val<a.val;
    };
};
nod mp[250010];
int f[maxn];
int found(int x)
{
    return x==f[x]? f[x]:f[x]=found(f[x]);
}
int n,m,l;
int main()
{
#ifdef shuaishuai
    freopen("C:\\Users\\hasee\\Desktop\\a.txt","r",stdin);
    // freopen("C:\\Users\\hasee\\Desktop\\b.txt","w",stdout);
    // freopen("C:\\Users\\hasee\\Desktop\\picture.in","r",stdin);

#endif
        scanf("%d%d%d",&n,&m,&l);
        LL support=0LL;
        for(int i=0; i<l; i++)
        {
            scanf("%d%d%d",&mp[i].x,&mp[i].y,&mp[i].val);
            support+=(LL)mp[i].val;
            mp[i].f=true;
        }
        for(int i=l; i<m; i++)
        {
            scanf("%d%d%d",&mp[i].x,&mp[i].y,&mp[i].val);
            mp[i].f=false;
        }
        sort(mp,mp+m);
        int cnt=1;
        LL need=0LL;
        for(int i=0; i<=n; i++)f[i]=i;
        for(int i=0; i<m; i++)
        {
            int x=mp[i].x,y=mp[i].y;
            int fx=found(x),fy=found(y);
            if(fx!=fy)
            {
             //   printf("%d %d %d\n",mp[i].x,mp[i].y,mp[i].val);
                f[fx]=fy;
                cnt++;
                if(mp[i].f) support-=(LL)mp[i].val;
                else need+=(LL)mp[i].val;
                if(cnt==n) break;
            }
        }
        //for(int i=1;i<=n;i++)printf("%d ",f[i]);printf("\n");
        if(support>=need&&m!=0&&cnt==n)puts("possible");
        else puts("impossible");
    return 0;
}
时间: 2024-08-01 22:45:48

hoj 13792 Model Railroad的相关文章

upc 2784 Model Railroad

Model Railroad 时间限制: 1 Sec  内存限制: 64 MB提交: 173  解决: 45[提交] [状态] [讨论版] [命题人:admin] 题目描述 Since childhood you have been fascinated by model railroads. Designing your own tracks,complicated intersections, train stations with miniatures of travellers, tra

国外火车模型杂志列表

1:64 Modeling Guide - Quarterly publication catering to the S scale model railroader Acadia Collectibles - Online store specializing in model railroad magazine backissues Atlantic Northeast Rails & Ports - Newsletter about the railroads, ports, inter

HOJ 题目分类

转自:http://blog.sina.com.cn/s/blog_65f3869301011a1o.html ******************************************************************************* 简单题(包括枚举,二分查找,(复杂)模拟,基础数据结构(栈.队列),杂题等 ****************************************************************************

cs224d problem set2 (三) 用RNNLM模型实现Language Model,来预测下一个单词的出现

今天将的还是cs224d 的problem set2 的第三部分习题, 原来国外大学的系统难度真的如此之大,相比之下还是默默地再天朝继续搬砖吧 (注意前方高能,一大批天书即将来袭) ''' Created on 2017年9月26日 @author: weizhen ''' import getpass import sys import time import numpy as np from copy import deepcopy from utils import calculate_p

Data Model for Message Receiver

1. Physical Data Model 2. SQL Statements drop database MessageReceiver go /*==============================================================*/ /* Database: MessageReceiver */ /*==============================================================*/ create dat

springMVC:modelandview,model,controller,参数传递

转载:http://blog.csdn.net/wm5920/article/details/8173480 1.web.xml 配置: copy <> ></> ></> > >> ></> ></> > ></> </> <> ></> ></> </> 这样,所有的.htm的请求,都会被Dispatche

NHibernate框架与BLL+DAL+Model+Controller+UI 多层架构十分相似--『Spring.NET+NHibernate+泛型』概述、知识准备及介绍(一)

原文://http://blog.csdn.net/wb09100310/article/details/47271555 1. 概述 搭建了Spring.NET+NHibernate的一个数据查询系统.之前没用过这两个框架,也算是先学现买,在做完设计之 后花了一周搭建成功了.其中,还加上了我的一些改进思想,把DAO和BLL之中相似且常用的增删改查通过泛型T抽象到了DAO和BLL的父类中,其DAO 和BLL子类只需继承父类就拥有了这些方法.和之前的一个数据库表(视图)对应一个实体,一个实体对应一

asp.net mvc 提交model 接收不了

[HttpPost]        //[ValidateInput(false)]        public ActionResult AddNews1(_54Young_News_Model.model.gou54contentall contentmodel, _54Young_News_Model.model.gou54user usermodel)        {} 发现用一些特殊符号提交不了, 然后以为说前端问题,把model去掉就可以了. 后面觉得是因为有特殊符号影响到转mod

Django操作model时,报错:AttributeError:’ProgrammingError’ object has no attribute ‘__traceback__’

原因:在Django项目下相应的应用下面的models.py配置的model(也就是class)没有创建成相应的表. 这是怎么回事呢? 首先,将models.py里面的model创建成对应的数据库表的执行命令(DOS命令)为:manage.py syncdb. 但是我自己的电脑上执行该命令时,显示.Unknown command:syncdb.执行,manage.py help后的确没有发现这个子命令.最后网上搜索发现这个命令已经在Django1.9里面取消了.并且stackoverflow里面