Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 你要把其中一些road变成单向边使得:每个town都有且只有一个入度


和上题一样...

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=1e5+, M=2e5+;
typedef long long ll;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} int n, m, u, v;
struct edge{int v, ne;} e[M<<];
int cnt=, h[N];
inline void ins(int u, int v) {
e[++cnt]=(edge){v, h[u]}; h[u]=cnt;
e[++cnt]=(edge){u, h[v]}; h[v]=cnt;
}
int vis[N], q[N], p, circle, flag[N];
int ve[M<<];
void dfs(int u) {
vis[u]=; q[++p]=u;
for(int i=h[u];i;i=e[i].ne) if(!ve[i]){
ve[i] = ve[i^] = ;
if(!vis[e[i].v]) dfs(e[i].v);
else circle=;
}
}
int main() {
freopen("in","r",stdin);
n=read(); m=read();
for(int i=; i<=m; i++) u=read(), v=read(), ins(u, v);
for(int i=; i<=n; i++) if(!vis[i]) {
p=; circle=; dfs(i);
int mx=;
for(int i=; i<=p; i++) {
if(flag[q[i]]) circle = ;
else flag[q[i]] = ;
mx = max(mx, q[i]);
}
if(!circle) flag[mx] = ;
}
int ans = ;
while(flag[ans+]) ans++;
puts(ans==n ? "TAK" : "NIE");
}

BZOJ 1116: [POI2008]CLO [连通分量]的更多相关文章

  1. BZOJ 1116: [POI2008]CLO

    1116: [POI2008]CLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 922  Solved: 514[Submit][Status][ ...

  2. BZOJ 1116 [POI2008]CLO(并查集)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1116 [题目大意] Byteotia城市有n个towns,m条双向roads.每条ro ...

  3. BZOJ 1116: [POI2008]CLO 并查集

    成立时当且仅当每个联通块都有环存在.一个连通块若有m个点,则必有多于m条有向边,可用并查集来维护. #include<cstdio> #include<iostream> #d ...

  4. 1116: [POI2008]CLO

    1116: [POI2008]CLO https://lydsy.com/JudgeOnline/problem.php?id=1116 分析: 单独考虑每个联通块的情况. 设这个联通块里有n个点,那 ...

  5. BZOJ 1116 [POI2008]CLO-Toll 并查集

    如果一个连通块是一个树的形态,则不合法,否则合法. 用并查集判断一下即可. #include <bits/stdc++.h> #define N 100005 #define M 2000 ...

  6. BZOJ1116: [POI2008]CLO

    1116: [POI2008]CLO Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 565  Solved: 303[Submit][Status] ...

  7. 【BZOJ1116】[POI2008]CLO 并查集

    [BZOJ1116][POI2008]CLO Description Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. ...

  8. Bzoj 1131[POI2008]STA-Station (树形DP)

    Bzoj 1131[POI2008]STA-Station (树形DP) 状态: 设\(f[i]\)为以\(i\)为根的深度之和,然后考虑从他父亲转移. 发现儿子的深度及其自己的深度\(-1\) 其余 ...

  9. bzoj 1123 [POI2008]BLO——点双连通分量

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1123 点双连通分量缩点,然后各种各样. 结果不会写了.比如新连边.记录一个点是割点缩成的点还 ...

随机推荐

  1. js第一课总结

    一. 当引用了一个src="demo.js"后,scrpit中间不能有js类的任何方法,都不会被执行. <!DOCTYPE html PUBLIC "-//W3C/ ...

  2. 基于TypeScript装饰器定义Express RESTful 服务

    前言 本文主要讲解如何使用TypeScript装饰器定义Express路由.文中出现的代码经过简化不能直接运行,完整代码的请戳:https://github.com/WinfredWang/expre ...

  3. javascript之fill()方法

    无意中看到fill这个方法,有些不解,起初以为是人家自定义的方法,后来才发觉原来不是,javascript里面是真的有这个方法,于是特地学习了下. fill()方法的作用是使用一个固定值来替换数组中的 ...

  4. myeclipse中git的使用

    1.右键项目,team-->commit,勾选修改了的文件,点击commit(将更新提交到本地仓库)2.右键项目,team-->pull,合并本地仓库和远程服务器仓库,pull后有一些文件 ...

  5. php 下载文件的头信息 Determine Content Type

    <?php if(!function_exists('mime_content_type')) { function mime_content_type($filename) { $mime_t ...

  6. Thinkphp5+PHPExcel实现批量上传表格数据功能

    http://www.jb51.net/article/129262.htm 1.首先要下载PHPExcel放到vendor文件夹下,我的路径是:项目/vendor/PHPExcel/,把下载的PHP ...

  7. fsockopen — 打开一个网络连接或者一个Unix套接字连接

    fsockopen (PHP 4, PHP 5, PHP 7) 说明 resource fsockopen ( string $hostname [, int $port = -1 [, int &a ...

  8. php数组根据某一个键值,把相同键值的合并生成一个新的二维数组

    http://blog.csdn.net/xyzchenxiaolin/article/details/51700485 源数据: $infos = array( array( 'a' => 3 ...

  9. 邓_tp_笔记

    <?phpnamespace app\teacher\controller;use think\Db;use app\common\model\Classcourse;use app\commo ...

  10. Cannot complete the install because one or more required items could not be found

    弄了一天的subclipse也没装上,郁闷~~~~~~~~ 无论采用本地安装还是站点安装都不行,在安装的时候显示错误: Cannot complete the install because one  ...