[luoguP3068] [USACO13JAN]派对邀请函Party Invitations(stl大乱交)
2017-08-16 14:48
267 查看
记录每一个编号在那些组中,可以用vector,这里选择链式前向星。
每一组用set
将被邀请的放到queue中
#include <set> #include <queue> #include <cstdio> #include <cstring> #include <iostream> #define N 1000001 using namespace std; int n, g, cnt, ans; int head , to , next ; queue <int> q; set <int> s ; set <int> :: iterator it; bool b ; inline int read() { int x = 0, f = 1; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1; for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; return x * f; } inline void add(int x, int y) { to[cnt] = y; next[cnt] = head[x]; head[x] = cnt++; } int main() { int i, j, k, x, u, v; n = read(); g = read(); memset(head, -1, sizeof(head)); for(i = 1; i <= g; i++) { k = read(); for(j = 1; j <= k; j++) { x = read(); s[i].insert(x); add(x, i); } } q.push(1); while(!q.empty()) { ans++; u = q.front(); q.pop(); for(i = head[u]; i ^ -1; i = next[i]) { v = to[i]; s[v].erase(u); it = s[v].begin(); if(s[v].size() == 1 && !b[*it]) { b[*it] = 1; q.push(*it); } } } printf("%d\n", ans); return 0; }
相关文章推荐
- 洛谷P3068 [USACO13JAN]派对邀请函Party Invitations
- 大力stl——P2202 [USACO13JAN]方块重叠Square Overlap
- [luoguP2701] [USACO5.3]巨大的牛棚Big Barn(DP)
- 洛谷P3070 [USACO13JAN]岛游记Island Travels
- [USACO13JAN]座位Seating
- [luoguP2982][USACO10FEB]慢下来Slowing down(dfs序 + 线段树)
- [luoguP2915] [USACO08NOV]奶牛混合起来Mixed Up Cows(DP)
- 【USACO 2.2.4】派对灯
- 状态压缩搜索——【USACO2.2.4】派对灯
- [luoguP3092] [USACO13NOV]没有找零No Change(状压DP + 二分)
- 离散-洛谷P2205 [USACO13JAN]画栅栏Painting the Fence
- luoguP4188 [USACO18JAN]Lifeguards S
- [luoguP1494] 岳麓山上打水 && [luoguP2744] [USACO5.3]量取牛奶Milk Measuring
- luoguP2701 [USACO5.3]巨大的牛棚Big Barn(极大子矩阵)
- [luogu1108&2687][USACO4.3]Buy Low, Buy Lower(STL乱搞+高精度)
- USACO section 3.2 Magic Squares(STL+广搜)
- [luoguP1849] [USACO12MAR]拖拉机Tractor(spfa)
- USACO section 3.2 Magic Squares(STL+广搜)
- 洛谷P2202 [USACO13JAN]方块重叠Square Overlap
- LuoguP2846[USACO08NOV]光开关Light Switching【线段树维护区间异或】By cellur925