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 ...
随机推荐
- mybatis基础犯错总结
1.关于mybatis的文件一般都是其mapper文件出错: 首先关于输入参数parameterType出错: (1)基本数据类型:如果输入参数只有一个,其数据类型可以是基本数据类型,也可以是自己定的 ...
- [DeeplearningAI笔记]序列模型1.3-1.4循环神经网络原理与反向传播公式
5.1循环序列模型 觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.3循环神经网络模型 为什么不使用标准的神经网络 假如将九个单词组成的序列作为输入,通过普通的神经网网络输出输出序列, 在 ...
- Tensorflow实现学习率衰减
Tensorflow实现学习率衰减 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 Deeplearning AI Andrew Ng Tensorflow1.2 API 学习率衰减 ...
- LeetCode-Insertion Sort List[AC源码]
package com.lw.leet5; /** * @ClassName:Solution * @Description: * Insertion Sort List * Sort a linke ...
- Mybatis多参数及实体对象传递
在使用Mybatis的时候,经常会有各种各样的参数传递,不同类型,不同个数的参数. 先上个例子: public List<LifetouchRelease> findOfficeL ...
- spring boot 2.0.3+spring cloud (Finchley)4、熔断器Hystrix
在分布式系统中服务与服务之间的依赖错综复杂,一种不可避免的情况就是某些服务会出现故障,导致依赖于他们的其他服务出现远程调度的线程阻塞.某个服务的单个点的请求故障会导致用户的请求处于阻塞状态,最终的结果 ...
- Keras学习笔记1--基本入门
""" 1.30s上手keras """ #keras的核心数据结构是“模型”,模型是一种组织网络层的方式,keras 的主要模型是Sequ ...
- LintCode 394: First Will Win
LintCode 394: First Will Win 题目描述 有n个硬币排成一条线.两个参赛者轮流从右边依次拿走1或2个硬币,直到没有硬币为止.拿到最后一枚硬币的人获胜. 请判定 第一个玩家 是 ...
- php跳转网络连接
laravel用 redirect 跳转 HTTP 即可.可以把网址看作路由 例如: if($newsInfo->type == 77){ return redirect('http://192 ...
- 【leetcode 简单】第二十题 合并两个有序数组
给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 说明: 初始化 nums1 和 nums2 的元素数量分别为 m 和 n. ...