题目链接:http://hihocoder.com/problemset/problem/1184

题意裸,写个博客记下输出姿势。

  1. /*
  2. ━━━━━┒ギリギリ♂ eye!
  3. ┓┏┓┏┓┃キリキリ♂ mind!
  4. ┛┗┛┗┛┃\○/
  5. ┓┏┓┏┓┃ /
  6. ┛┗┛┗┛┃ノ)
  7. ┓┏┓┏┓┃
  8. ┛┗┛┗┛┃
  9. ┓┏┓┏┓┃
  10. ┛┗┛┗┛┃
  11. ┓┏┓┏┓┃
  12. ┛┗┛┗┛┃
  13. ┓┏┓┏┓┃
  14. ┃┃┃┃┃┃
  15. ┻┻┻┻┻┻
  16. */
  17. #include <algorithm>
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <cstring>
  21. #include <climits>
  22. #include <complex>
  23. #include <fstream>
  24. #include <cassert>
  25. #include <cstdio>
  26. #include <bitset>
  27. #include <vector>
  28. #include <deque>
  29. #include <queue>
  30. #include <stack>
  31. #include <ctime>
  32. #include <set>
  33. #include <map>
  34. #include <cmath>
  35. using namespace std;
  36. #define fr first
  37. #define sc second
  38. #define cl clear
  39. #define BUG puts("here!!!")
  40. #define W(a) while(a--)
  41. #define pb(a) push_back(a)
  42. #define Rint(a) scanf("%d", &a)
  43. #define Rll(a) scanf("%lld", &a)
  44. #define Rs(a) scanf("%s", a)
  45. #define Cin(a) cin >> a
  46. #define FRead() freopen("in", "r", stdin)
  47. #define FWrite() freopen("out", "w", stdout)
  48. #define Rep(i, len) for(int i = 0; i < (len); i++)
  49. #define For(i, a, len) for(int i = (a); i < (len); i++)
  50. #define Cls(a) memset((a), 0, sizeof(a))
  51. #define Clr(a, x) memset((a), (x), sizeof(a))
  52. #define Full(a) memset((a), 0x7f7f, sizeof(a))
  53. #define lrt rt << 1
  54. #define rrt rt << 1 | 1
  55. #define pi 3.14159265359
  56. #define RT return
  57. #define lowbit(x) x & (-x)
  58. #define onenum(x) __builtin_popcount(x)
  59. typedef long long LL;
  60. typedef long double LD;
  61. typedef unsigned long long ULL;
  62. typedef pair<int, int> pii;
  63. typedef pair<string, int> psi;
  64. typedef pair<LL, LL> pll;
  65. typedef map<string, int> msi;
  66. typedef vector<int> vi;
  67. typedef vector<LL> vl;
  68. typedef vector<vl> vvl;
  69. typedef vector<bool> vb;
  70.  
  71. const int maxn = ;
  72. const int maxm = ;
  73. typedef struct Edge {
  74. int u, v;
  75. int next, i;
  76. bool cut;
  77. Edge() {}
  78. Edge(int uu, int vv, int ii) : u(uu), v(vv), i(ii) {}
  79. }Edge;
  80.  
  81. Edge edge[maxm];
  82. int head[maxn], ecnt;
  83. int n, m;
  84. int dfn[maxn];
  85. int low[maxn];
  86. bool vis[maxn];
  87. bool cut[maxn];
  88. vi bridge;
  89. int st[maxn], top;
  90. int belong[maxn], bcnt;
  91. vi tmp;
  92. int ret;
  93.  
  94. void init() {
  95. Clr(head, -); Cls(low); Cls(dfn);
  96. Cls(vis); Cls(cut); Cls(st); ret = ;
  97. bcnt = ; top = ; ecnt = ; bridge.cl();
  98. }
  99.  
  100. void adde(int uu, int vv, int ii) {
  101. edge[ecnt] = Edge(uu, vv, ii);
  102. edge[ecnt].cut = ;
  103. edge[ecnt].next = head[uu];
  104. head[uu] = ecnt++;
  105. }
  106.  
  107. void tarjan(int u, int d, int p) {
  108. low[u] = dfn[u] = d;
  109. st[++top] = u;
  110. vis[u] = ;
  111. for(int i = head[u]; ~i; i=edge[i].next) {
  112. int v = edge[i].v;
  113. int id = edge[i].i;
  114. if(p == id) continue;
  115. if(!dfn[v]) {
  116. tarjan(v, d+, id);
  117. low[u] = min(low[u], low[v]);
  118. if(low[v] > dfn[u]) {
  119. bridge.pb(i);
  120. edge[i].cut = edge[i^].cut = ;
  121. }
  122. }
  123. else low[u] = min(low[u], dfn[v]);
  124. }
  125. if(low[u] == dfn[u]) {
  126. tmp.cl();
  127. int v;
  128. bcnt = 0x7f7f7f;
  129. do {
  130. v = st[top--];
  131. vis[v] = ;
  132. bcnt = min(bcnt, v);
  133. tmp.pb(v);
  134. }while(v != u);
  135. Rep(i, tmp.size()) belong[tmp[i]] = bcnt;
  136. ret++;
  137. }
  138. }
  139.  
  140. int main() {
  141. // FRead();
  142. int u, v;
  143. while(~scanf("%d%d", &n, &m)) {
  144. init();
  145. For(i, , m+) {
  146. Rint(u); Rint(v);
  147. adde(u, v, i);
  148. adde(v, u, i);
  149. }
  150. For(i, , n+) {
  151. if(!dfn[i]) tarjan(i, , -);
  152. }
  153. printf("%d\n", ret);
  154. For(i, , n+) printf("%d ", belong[i]);
  155. printf("\n");
  156. }
  157. RT ;
  158. }

[HIHO1184]连通性二·边的双连通分量(双连通分量)的更多相关文章

  1. hihoCoder 1184 连通性二·边的双连通分量

    #1184 : 连通性二·边的双连通分量 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在基本的网络搭建完成后,学校为了方便管理还需要对所有的服务器进行编组,网络所的老 ...

  2. hihoCoder #1184 : 连通性二·边的双连通分量(边的双连通分量模板)

    #1184 : 连通性二·边的双连通分量 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在基本的网络搭建完成后,学校为了方便管理还需要对所有的服务器进行编组,网络所的老 ...

  3. HohoCoder 1184 : 连通性二·边的双连通分量(+原理证明)

    1184 : 连通性二·边的双连通分量 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在基本的网络搭建完成后,学校为了方便管理还需要对所有的服务器进行编组,网络所的老师 ...

  4. 高可用Mysql架构_Mysql主从复制、Mysql双主热备、Mysql双主双从、Mysql读写分离(Mycat中间件)、Mysql分库分表架构(Mycat中间件)的演变

    [Mysql主从复制]解决的问题数据分布:比如一共150台机器,分别往电信.网通.移动各放50台,这样无论在哪个网络访问都很快.其次按照地域,比如国内国外,北方南方,这样地域性访问解决了.负载均衡:M ...

  5. 高可用Mysql架构_Mycat集群部署(HAProxy + 两台Mycat+Mysql双主双从)

    既然大家都知道了Mysql分布式在大型网站架构中的作用,在这里就不再阐述.本片博客文章是基于我曾经搭建过的一个Mysql集群基础上实现的,实现过双主热备.读写分离.分库分表. 博客链接:http:// ...

  6. windows2003服务器双线双IP双网卡设置方法

    双线双ip很好,网通用户访问网通线路,电信用户访问电信线路.但很多人会选用导入静态路由表,这个办法看似完美,其实问题很多. 1.电信用户如果被解析到网通的ip上,服务器根据路由表会返回电信线路,但用户 ...

  7. Windows 10、Ubuntu 18.04 双系统 双硬盘 安装经验总结

    首先说明,我假设读者懂得分区.安装系统,所以不再深入讨论具体操作. 如果需要手把手教程,建议先参考其它Windows中加装Linux的相关文章. 网上其它文章.教程的常见问题是,各家机器配置不一样,安 ...

  8. 基于双XCKU060+双C6678 的双FMC接口40G光纤传输加速计算卡

    基于双XCKU060+双C6678 的双FMC接口40G光纤传输加速计算卡 一.板卡概述 板卡采用基于双FPGA+双DSP的信号采集综合处理硬件平台,板卡大小360mmx217mm.板卡两片FPGA提 ...

  9. 基于双XCKU060+双C6678 的双FMC接口40G光纤传输加速计算卡381

    一.板卡概述 板卡采用基于双FPGA+双DSP的信号采集综合处理硬件平台,板卡大小360mmx217mm.板卡两片FPGA提供两个FMC接口,4路QSFP+接口:每片FPGA挂接2簇32-bit DD ...

随机推荐

  1. 将eclipse的应用程序打包成.exe

    转自:http://blog.163.com/loveshijie_1991/blog/static/1760553112012102573437156/ 参考:http://blog.csdn.ne ...

  2. c#之反射总结

     1.了解什么事程序集 2.加载程序集 首先要加载需要加载的程序集,然后找到指定的类型,进而往下进行动态加载. 要加载的程序集中的内容: public class Class1:Person { pr ...

  3. Video Toolbox:读写解码回调函数CVImageBufferRef的YUV图像

    本文档基于H.264的解码,介绍读写Video Toolbox解码回调函数参数CVImageBufferRef中的YUV或RGB数据的方法,并给出CVImageBufferRef生成灰度图代码.方便调 ...

  4. Android keyevent 中的各个值

    Android keyevent 中的各个值,在使用adb shell input 的时候用得到. 是从http://blog.csdn.net/huiguixian/article/details/ ...

  5. Text Template Transformation Toolkit

    Text Template Transformation Toolkit       1.且算简介         笔者以一个英文字母和一个数字取了一个简单的名字.名唤"T4"(名 ...

  6. 在ubuntu16.04 下安装haproxy 1.5.11 做tcp负载均衡

    由于haproxy需要FQ下载,所以从csdn下载了较为新版的haproxy1.5.11,安装过程如下: 1. 解压haproxy-1.5.11.tar.gz : tar xzvf haproxy-1 ...

  7. BAT CMD 批处理文件脚本 -2

    http://checheng1988.blog.51cto.com/4725808/1090733 在很多windows程序中会见到很多用扩展名为.bat和.cmd结尾的文件,那么这些文件能干什么呢 ...

  8. c++ uuid生成法则

    http://www.jb51.net/LINUXjishu/39614.html CentOS #include <uuid/uuid.h> 找不到文件解决方法: sudo yum in ...

  9. IntelliJ IDEA的Maven项目在修改时报java.lang.OutOfMemoryError: PermGen space异常

    什么也不说了---内存溢出,遇见太多回了,下面是解决方式: 1.在项目设置中新建Maven,然后设置VM: 2. 在pom.xml添加下面2个插件,一个是jrebel的,一个是jetty的 <b ...

  10. vc终端输入结束符

    操作系统使用不同的值作为文件结束符.Windows上我们通过键入ctrl+z键作为文件结束符.Unix系统中,包括Mac OS-X机器,通常用ctrl+d作为文件结束符.用VC++6.0的时候,要输入 ...