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 ...
随机推荐
- 清除localstorage
h5本地存储localStorage,sessionStorage. localStorage是没有失效时间的,sessionStorage的声明周期是浏览器的生命周期. 当浏览器关闭时,sessio ...
- nginx 前后分离,地址重写,url匹配中遇到的问题
我遇到的问题: 前端用vue的路由做页面路由,后台用spring mvc做数据接口,但是遇到路由地址和接口地址无法区分的问题,导致nginx无法正确准发比如: 1)http://127.0.0.1/i ...
- myeclipse注册码,可以用到2016年
myeclipse注册码,可以用到2016年 xiangyang kLR8ZF-655954-61677756068297221
- MongoDB - MongoDB CRUD Operations, Update Documents
Update Methods MongoDB provides the following methods for updating documents in a collection: Method ...
- 可编辑表格(Editable Table)
需求分析 1.单击table的每个cell后,给cell加上一个尺寸相当的input; 2.input后把value传给cell的innerHTML; 3.失焦后删除input. HTML <! ...
- Tomcat处理一个http请求的过程
假设来自客户的请求为: http://localhost:8080/wsota/wsota_index.jsp 1) 请求被发送到本机端口8080,被在那里侦听的Coyote HTTP/1.1 Con ...
- 强制换行CSS样式
语法: word-wrap : normal | break-word 取值: normal :? 默认值.允许内容顶开指定的容器边界 break-word :? 内容将在边界内换行.如果需要,词内换 ...
- 关于jQuery UI 使用心得及技巧
1 jQuery UI 有时你仅仅是为了实现一个渐变的动画效果而不得不把javascrip 重新学习一遍然后书写大量代码.直到jQuery的出现,让开发人员从一大堆繁琐的js代码中解脱,取而代之几行j ...
- DHTML Object Model&DHTML&DOM
DHTML Object Model:DHTML对象模型,利用DHTML Object Model可以单独操作页面上的对象,每个HTML标记通过它的ID和NAME属性被操纵,每个对象都具有自己的属性. ...
- CF 900B
CF 900B Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Descript ...