洛谷P3068 [USACO13JAN]派对邀请函Party Invitations
P3068 [USACO13JAN]派对邀请函Party Invitations
题目描述
Farmer John is throwing a party and wants to invite some of his cows to show them how much he cares about his herd. However, he also wants to invite the smallest possible number of cows, remembering all too well the disaster that resulted the last time he invited too many cows to a party.
Among FJ's cows, there are certain groups of friends that are hard to separate. For any such group (say, of size k), if FJ invites at least k-1 of the cows in the group to the party, then he must invite the final cow as well, thereby including the entire group. Groups can be of any size and may even overlap with each-other, although no two groups contain exactly the same set of members. The sum of all group sizes is at most 250,000.
Given the groups among FJ's cows, please determine the minimum number of cows FJ can invite to his party, if he decides that he must definitely start by inviting cow #1 (his cows are conveniently numbered 1..N, with N at most 1,000,000).
FJ正在举行派对,并想邀请他的一些奶牛参加以显示FJ多么关心他们,同时,他也希望邀请奶牛的数量最少,有了上一次派对的后果,他不要邀请过多的奶牛参加派对。
在FJ的奶牛中,有一些奶牛不能分开。 对于任何这样的奶牛群,(如果某个群的奶牛数量为k),当FJ邀请组中的至少k-1个奶牛参加派对时,他必须邀请最后的一头奶牛,从而包括整个组。 组可以是任何大小,并且甚至可以彼此重叠,但是没有两个组包含完全相同的奶牛。组的总数<=250,000。
考虑到FJ的牛群中的朋友关系群体的情况下,请你确定FJ可以邀请参加他的派对的奶牛的最小数量,开始前他必须先邀请编号为1的奶牛(为了方便,FJ的的奶牛方编号为1..N,N<=1,000,000)
输入输出格式
输入格式:
Line 1: Two space-separated integers: N (the number of cows), and G (the number of groups).
- Lines 2..1+G: Each line describes a group of cows. It starts with an integer giving the size S of the group, followed by the S cows in the group (each an integer in the range 1..N).
第一行:两个空格分隔的整数:N和G。分别表示奶牛的数量和朋友组的的数量
接下来2到G+1行:每一行描述一群牛。它始于一个整数,表示这个组的大小,接下来每一个数表示一只奶牛的编号(编号在1到n之间,表示这只奶牛在这个朋友组里)
输出格式:
- Line 1: The minimum number of cows FJ can invite to his party.
共一行,一个数:表示FJ最少可以邀请的牛的数量
输入输出样例
说明
There are 10 cows and 4 groups. The first group contains cows 1 and 3, and so on.
In addition to cow #1, FJ must invite cow #3 (due to the first group constraint), cow #4 (due to the second group constraint), and also cow #2 (due to the final group constraint).
样例一共10头牛和4组。 第一组包含奶牛1和3,接下来的组也类似
除了奶牛#1,FJ还必须邀请牛#3(由于第一组约束),牛#4(由于第二组约束)和牛#2(由于最终组约束)。
感谢mangoyang 提供翻译
#include<iostream>
#include<cstdio>
#include<set>
#include<queue>
#define maxn 1000001
using namespace std;
int num,head[maxn];
struct node{int to,pre;}e[maxn];
bool b[maxn];
queue<int>q;
set<int>s[maxn];
int n,m,x,y,ans;
void Insert(int from,int to){
e[++num].to=to;
e[num].pre=head[from];
head[from]=num;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
scanf("%d",&x);
for(int j=;j<=x;j++){
scanf("%d",&y);
Insert(y,i);
s[i].insert(y);
}
}
q.push();
while(!q.empty()){
int now=q.front();q.pop();
for(int i=head[now];i;i=e[i].pre){
int to=e[i].to;
s[to].erase(now);
if(s[to].size()==){
set<int>::iterator it=s[to].begin();
if(!b[*it])b[*it]=,q.push(*it),ans++;
}
}
}
printf("%d",ans+);
}
洛谷P3068 [USACO13JAN]派对邀请函Party Invitations的更多相关文章
- 洛谷 P3068 [USACO13JAN]派对邀请函Party Invitations
P3068 [USACO13JAN]派对邀请函Party Invitations 题目描述 Farmer John is throwing a party and wants to invite so ...
- [luoguP3068] [USACO13JAN]派对邀请函Party Invitations(stl大乱交)
传送门 记录每一个编号在那些组中,可以用vector,这里选择链式前向星. 每一组用set 将被邀请的放到queue中 #include <set> #include <queue& ...
- [洛谷P3697]开心派对小火车
题目:洛谷P3697 题目大意是有各站停列车(慢车,相邻2站时间A)和特急列车(相邻2站时间B),特急列车在特定站点停靠. 现在加一种快速列车(相邻2站时间C,A>C>B),停靠K站(包括 ...
- [洛谷201704R1]开心派对小火车
OJ题号:洛谷P3697 思路: 贪心.首先从起点出发,开特急电车,对于每一个特急车站$s_{i}$,分别下一次车,计算从当前车站$s_{i}$出发坐各停电车在指定时限内$t$最远能够到达的车站$r_ ...
- 洛谷银牛派对SPFA
题目描述 One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the b ...
- 洛谷 P3071 [USACO13JAN]座位Seating-线段树区间合并(判断找,只需要最大前缀和最大后缀)+分治+贪心
P3071 [USACO13JAN]座位Seating 题目描述 To earn some extra money, the cows have opened a restaurant in thei ...
- 洛谷P2202 [USACO13JAN]方块重叠Square Overlap
P2202 [USACO13JAN]方块重叠Square Overlap 题目描述 Farmer John is planning to build N (2 <= N <= 50,000 ...
- 洛谷P3070 [USACO13JAN]岛游记Island Travels
P3070 [USACO13JAN]岛游记Island Travels 题目描述 Farmer John has taken the cows to a vacation out on the oce ...
- 洛谷 P3071 [USACO13JAN]座位Seating(线段树)
P3071 [USACO13JAN]座位Seating 题目链接 思路: 一开始把题给读错了浪费了好多时间呜呜呜. 因为第二个撤离操作是区间修改,所以我们可以想到用线段树来做.对于第一个操作,我们只需 ...
随机推荐
- css3加载spinner
使用代码制作一个加载旋转器spinner 实现的原理是: 1.两个圆圈,其中一个圆圈是使用pseudo元素(:before)产生 2.由pseudo元素生成的圆通过负数的z-index而作用在下面 3 ...
- Selenium-百度登录简单例子
实现: 百度web端登录,手动输入验证码 #! /usr/bin/env python #coding=utf-8 from selenium import webdriver import time ...
- Git_错误_02_error: src refspec master does not match any
现象:在一个目录下初始化仓库之后,就开始push到github,结果出现了这个错误. 错因:初始化仓库之后,并没有使用git add,git commit 命令将文件添加到git仓库中,所以仓库为空, ...
- android开发中图片优化步骤
android开发中图片优化方法 1.图片加载方法,方便用户加载图片 /*** * 加载本地图片 * @param context:主运行函数实例 * @param bitAdress:图片地址,一般 ...
- python中zip()函数基本用法
zip()函数接受一系列可迭代对象作为参数,将不同对象中相对应的元素打包成一个元组(tuple),返回由这些元组组成的list列表,如果传入的参数的长度不等,则返回的list列表的长度和传入参数中 ...
- JS图表工具 ---- Highcharts
Highcharts 是一个用纯 JavaScript编写的一个图表库, 能够很简单便捷的在web网站或是 web 应用程序添加有交互性的图表,并且免费提供给个人学习.个人网站和非商业用途使用. Hi ...
- Parallel Programming-使用CancellationTokenSource调度并行运行的Task
本文主要介绍使用CancellationTokenSource调度并行运行的Task. 一.使用场景 有多个Task并行运行时,如果其中一个Task所运行的程序出现异常,我们想马上终止所有待执行的Ta ...
- Poj1012_Joseph
一.Description The Joseph's problem is notoriously known. For those who are not familiar with the ori ...
- 用Word编辑cnblogs的博文并发布
听说可以用Word直接编辑文件发布博客,请教加研究,终于配置成功,先分享如下: 1. 在www.cnblogs.com上注册用户. 2. 打开Word,选择博客文章 3. 点击管理账户,新建或更改,按 ...
- SEO优化-伪静态-URLRewrite 详解
下面是文章是我在网上看到的,觉得写的还不错,我拿过来,修改了一些作者没有说到的地方....... 1. 在apache中配置 2. 用URLRewrite(详细:重点是UrlRewrite+Strut ...