IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E - Bear and Forgotten Tree 2 链表
思路:先不考虑1这个点,求有多少个连通块,每个连通块里有多少个点能和1连,这样就能确定1的度数的上下界。
求连通块用链表维护。
- #include<bits/stdc++.h>
- #define LL long long
- #define fi first
- #define se second
- #define mk make_pair
- #define PII pair<int, int>
- #define PLI pair<LL, int>
- #define ull unsigned long long
- using namespace std;
- const int N = 3e5 + ;
- const int inf = 0x3f3f3f3f;
- const LL INF = 0x3f3f3f3f3f3f3f3f;
- const int mod = ;
- const int Mod = 1e9 + ;
- int n, m, k, tot, pre, cnt1, cnt2;
- bool vis[N], ok[N];
- vector<int> ban[N];
- struct node {
- int id, nx;
- } Link[N];
- void add(int id) {
- Link[tot].id = id;
- Link[tot].nx = Link[].nx;
- Link[].nx = tot++;
- }
- int main() {
- Link[].nx = -; tot = ;
- scanf("%d%d%d", &n, &m, &k);
- cnt1 = ;
- for(int i = ; i <= m; i++) {
- int u, v;
- scanf("%d%d", &u, &v);
- ban[u].push_back(v);
- ban[v].push_back(u);
- if(u == ) ok[v] = true;
- if(v == ) ok[u] = true;
- }
- for(int i = ; i <= n; i++) add(i);
- int down = , up = ;
- while(Link[].nx != -) {
- int cnt = ;
- queue<int> que;
- que.push(Link[Link[].nx].id);
- Link[].nx = Link[Link[].nx].nx;
- while(!que.empty()) {
- int u = que.front(); que.pop();
- if(!ok[u]) cnt++;
- for(int b : ban[u]) vis[b] = true;
- pre = ;
- for(int i = Link[].nx; ~i; i = Link[i].nx) {
- int to = Link[i].id;
- if(!vis[to]) {
- que.push(to);
- Link[pre].nx = Link[i].nx;
- } else pre = i;
- }
- for(int b : ban[u]) vis[b] = false;
- }
- if(!cnt) {
- puts("impossible");
- return ;
- }
- down++;
- up += cnt;
- }
- if(k >= down && k <= up) puts("possible");
- else puts("impossible");
- return ;
- }
- /*
- */
IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E - Bear and Forgotten Tree 2 链表的更多相关文章
- VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3
C. Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) B. Bear and Compressing
B. Bear and Compressing 题目链接 Problem - B - Codeforces Limak is a little polar bear. Polar bears h ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E. Bear and Forgotten Tree 2 bfs set 反图的生成树
E. Bear and Forgotten Tree 2 题目连接: http://www.codeforces.com/contest/653/problem/E Description A tre ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) D. Delivery Bears 二分+网络流
D. Delivery Bears 题目连接: http://www.codeforces.com/contest/653/problem/D Description Niwel is a littl ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) C. Bear and Up-Down 暴力
C. Bear and Up-Down 题目连接: http://www.codeforces.com/contest/653/problem/C Description The life goes ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) B. Bear and Compressing 暴力
B. Bear and Compressing 题目连接: http://www.codeforces.com/contest/653/problem/B Description Limak is a ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A. Bear and Three Balls 水题
A. Bear and Three Balls 题目连接: http://www.codeforces.com/contest/653/problem/A Description Limak is a ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2)——A - Bear and Three Balls(unique函数的使用)
A. Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- CodeForces 653 A. Bear and Three Balls——(IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2))
传送门 A. Bear and Three Balls time limit per test 2 seconds memory limit per test 256 megabytes input ...
随机推荐
- bzoj 2530 [Poi2011]Party 构造
2530: [Poi2011]Party Time Limit: 10 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 364 Solved: ...
- Centos7单机部署ELK
一. 简介 1.1 介绍 ELK是三个开源工具组成,简单解释如下: Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风 ...
- python---Scrapy模块的使用(一)
Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 其可以应用在数据挖掘,信息处理或存储历史数据等一系列的程序中. Scrapy 使用了 Twisted异步网络库来处理网络通讯.整体 ...
- CCPC2018-A-Buy and Resell
Problem Description The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1 ...
- 【BZOJ】2154: Crash的数字表格 莫比乌斯反演
[题意]给定n,m,求Σlcm(i,j),1<=i<=n,1<=j<=m,n,m<=10^7. [算法]数论(莫比乌斯反演) [题解] $$ans=\sum_{i\leq ...
- 【BZOJ】1087: [SCOI2005]互不侵犯King
[算法]状态压缩型DP [题解]http://www.cnblogs.com/xtx1999/p/4620227.html (orz) https://www.cnblogs.com/zbtrs/p/ ...
- Let's Encrypt 免费通配 https 签名证书 安装方法
安装环境 centOs7 主要通过 acme.sh (bash脚本)来注册签名 git地址:https://github.com/Neilpang/acme.sh 申请证书流程 1.申请证书-> ...
- NYOJ 163 Phone List (字符串处理 字典树)
题目链接 描述 Given a list of phone numbers, determine if it is consistent in the sense that no number is ...
- 1-spring xml 和 注解 解析过程
spring mvc 入口 DispatcherServlet,类关系图如下所示 DispatcherServlet 就是一个 Servlet,那Servlet 的初始化方法 init()在哪里,通过 ...
- (转)USB的描述符及各种描述符之间的依赖关系
全文链接:http://justmei.blog.163.com/blog/static/11609985320102421659260/?latestBlog 1 推荐 [原创] USB入门系列之七 ...