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 链表的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 009.C++ const使用

    1.引例 class complex { public: complex(, ) : re (r), im (i) {} complex& operator += (const complex ...

  2. 手脱PE Pack v1.0

    1.PEID查壳 PE Pack v1.0 2.载入OD,一上来就这架势,先F8走着 > / je ; //入口点 -\E9 C49D0000 jmp Pepack_1.0040D000 004 ...

  3. centos7 ffmpeg安装

    #Nux Dextop库依赖于EPEL库,所有要先安装EPEL库yum -y install epel-release #安装Nux Dextop库rpm -Uvh http://li.nux.ro/ ...

  4. Spring 多数据源 @Transactional 注解事务管理

    在 Spring,MyBatis 下两个数据源,通过 @Transactional 注解 配置简单的事务管理 spring-mybatis.xml <!--******************* ...

  5. POJ 2007 Scrambled Polygon 极角序 水

    LINK 题意:给出一个简单多边形,按极角序输出其坐标. 思路:水题.对任意两点求叉积正负判断相对位置,为0则按长度排序 /** @Date : 2017-07-13 16:46:17 * @File ...

  6. SQL语句(二十二)—— 权限授予和回收(作业练习)

    CREATE TABLE course ( Cno ) NOT NULL, Cname ) DEFAULT NULL, Cpno ) DEFAULT NULL, Ccredit smallint DE ...

  7. C11线程管理:原子变量&单调函数

    1.原子变量 C++11提供了原子类型std::atomic<T>,可以使用任意类型作为模板参数,使用原子变量就不需要使用互斥量来保护该变量,用起来更加简洁. 举个例子,如果要做一个计数器 ...

  8. java中集合去重2

    1.对集合中的自动定义的对象去重: 自定义Person类,同时复写hashCode和equals方法 package collection; public class Person { private ...

  9. 【BZOJ2683】简单题 [分治][树状数组]

    简单题 Time Limit: 50 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 你有一个N*N的棋盘,每个格子内有一 ...

  10. 2017ACM暑期多校联合训练 - Team 2 1006 HDU 6050 Funny Function (找规律 矩阵快速幂)

    题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e ...