Go Deeper

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3435    Accepted Submission(s): 1125

Problem Description
Here is a procedure's pseudocode:

go(int dep, int n, int m)
begin
output the value of dep.
if dep < m and x[a[dep]] + x[b[dep]] != c[dep] then go(dep + 1, n, m)
end

In this code n is an integer. a, b, c and x are 4 arrays of integers. The index of array always starts from 0. Array a and b consist of non-negative integers smaller than n. Array x consists of only 0 and 1. Array c consists of only 0, 1 and 2. The lengths of array a, b and c are m while the length of array x is n. Given the elements of array a, b, and c, when we call the procedure go(0, n, m) what is the maximal possible value the procedure may output?

 
Input
There are multiple test cases. The first line of input is an integer T (0 < T ≤ 100), indicating the number of test cases. Then T test cases follow. Each case starts with a line of 2 integers n and m (0 < n ≤ 200, 0 < m ≤ 10000). Then m lines of 3 integers follow. The i-th(1 ≤ i ≤ m) line of them are ai-1 ,bi-1 and ci-1 (0 ≤ ai-1, bi-1 < n, 0 ≤ ci-1 ≤ 2).
 
Output
For each test case, output the result in a single line.
 
Sample Input
3
2 1
0 1 0
2 1
0 0 0
2 2
0 1 0
1 1 2
 
Sample Output
1
1
2
 
Author
CAO, Peng
 
Source
 
Recommend
zhouzeyong
 
 
 
解析:
  一定要明确 是哪两个点
  然后建图一定要明确怎么建
  二分定要写对
 
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <sstream>
  4. #include <cstring>
  5. #include <map>
  6. #include <cctype>
  7. #include <set>
  8. #include <vector>
  9. #include <stack>
  10. #include <queue>
  11. #include <algorithm>
  12. #include <cmath>
  13. #include <bitset>
  14. #define rap(i, a, n) for(int i=a; i<=n; i++)
  15. #define rep(i, a, n) for(int i=a; i<n; i++)
  16. #define lap(i, a, n) for(int i=n; i>=a; i--)
  17. #define lep(i, a, n) for(int i=n; i>a; i--)
  18. #define rd(a) scanf("%d", &a)
  19. #define rlld(a) scanf("%lld", &a)
  20. #define rc(a) scanf("%c", &a)
  21. #define rs(a) scanf("%s", a)
  22. #define pd(a) printf("%d\n", a);
  23. #define plld(a) printf("%lld\n", a);
  24. #define pc(a) printf("%c\n", a);
  25. #define ps(a) printf("%s\n", a);
  26. #define MOD 2018
  27. #define LL long long
  28. #define ULL unsigned long long
  29. #define Pair pair<int, int>
  30. #define mem(a, b) memset(a, b, sizeof(a))
  31. #define _ ios_base::sync_with_stdio(0),cin.tie(0)
  32. //freopen("1.txt", "r", stdin);
  33. using namespace std;
  34. const int maxn = 1e5 + , INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
  35. int n, m;
  36. int a[maxn], b[maxn], c[maxn];
  37. vector<int> G[maxn];
  38. int sccno[maxn], low[maxn], vis[maxn], scc_clock, scc_cnt;
  39. stack<int> S;
  40. void init()
  41. {
  42. for(int i = ; i < maxn; i++) G[i].clear();
  43. mem(sccno, );
  44. mem(low, );
  45. mem(vis, );
  46. scc_clock = scc_cnt = ;
  47. }
  48.  
  49. void dfs(int u)
  50. {
  51. low[u] = vis[u] = ++scc_clock;
  52. S.push(u);
  53. for(int i = ; i < G[u].size(); i++)
  54. {
  55. int v = G[u][i];
  56. if(!vis[v])
  57. {
  58. dfs(v);
  59. low[u] = min(low[u], low[v]);
  60. }
  61. else if(!sccno[v])
  62. low[u] = min(low[u], vis[v]);
  63. }
  64. if(vis[u] == low[u])
  65. {
  66. scc_cnt++;
  67. for(;;)
  68. {
  69. int x = S.top(); S.pop();
  70. sccno[x] = scc_cnt;
  71. if(x == u) break;
  72. }
  73. }
  74. }
  75.  
  76. void build(int mid)
  77. {
  78. for(int i = ; i <= mid; i++)
  79. {
  80. if(c[i] == )
  81. {
  82. G[a[i] << | ].push_back(b[i] << );
  83. G[b[i] << | ].push_back(a[i] << );
  84. }
  85. else if(c[i] == )
  86. {
  87. G[a[i] << | ].push_back(b[i] << | );
  88. G[b[i] << | ].push_back(a[i] << | );
  89. G[a[i] << ].push_back(b[i] << );
  90. G[b[i] << ].push_back(a[i] << );
  91. }
  92. else if(c[i] == )
  93. {
  94. G[a[i] << ].push_back(b[i] << | );
  95. G[b[i] << ].push_back(a[i] << | );
  96. }
  97. }
  98. }
  99.  
  100. bool check()
  101. {
  102. for(int i = ; i < n * ; i += )
  103. if(sccno[i] == sccno[i + ])
  104. return false;
  105. return true;
  106. }
  107.  
  108. int main()
  109. {
  110. int T;
  111. rd(T);
  112. while(T--)
  113. {
  114. init();
  115. rd(n), rd(m);
  116. for(int i = ; i < m; i++)
  117. {
  118. rd(a[i]), rd(b[i]), rd(c[i]);
  119. }
  120. int l = , r = m;
  121. while(l + < r)
  122. {
  123. init();
  124. int mid = (l + r) / ;
  125. build(mid);
  126. for(int i = ; i < n * ; i++)
  127. if(!vis[i]) dfs(i);
  128. if(check()) l = mid;
  129. else r = mid;
  130. }
  131. pd(l + );
  132.  
  133. }
  134.  
  135. return ;
  136. }
 
 
 

Go Deeper

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3435    Accepted Submission(s): 1125

Problem Description
Here is a procedure's pseudocode:

go(int dep, int n, int m)
begin
output the value of dep.
if dep < m and x[a[dep]] + x[b[dep]] != c[dep] then go(dep + 1, n, m)
end

In this code n is an integer. a, b, c and x are 4 arrays of integers. The index of array always starts from 0. Array a and b consist of non-negative integers smaller than n. Array x consists of only 0 and 1. Array c consists of only 0, 1 and 2. The lengths of array a, b and c are m while the length of array x is n. Given the elements of array a, b, and c, when we call the procedure go(0, n, m) what is the maximal possible value the procedure may output?

 
Input
There are multiple test cases. The first line of input is an integer T (0 < T ≤ 100), indicating the number of test cases. Then T test cases follow. Each case starts with a line of 2 integers n and m (0 < n ≤ 200, 0 < m ≤ 10000). Then m lines of 3 integers follow. The i-th(1 ≤ i ≤ m) line of them are ai-1 ,bi-1 and ci-1 (0 ≤ ai-1, bi-1 < n, 0 ≤ ci-1 ≤ 2).
 
Output
For each test case, output the result in a single line.
 
Sample Input
3
2 1
0 1 0
2 1
0 0 0
2 2
0 1 0
1 1 2
 
Sample Output
1
1
2
 
Author
CAO, Peng
 
Source
 
Recommend
zhouzeyong
 

Go Deeper HDU - 3715(2 - sat 水题 妈的 智障)的更多相关文章

  1. hdu 1106:排序(水题,字符串处理 + 排序)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  2. HDU 4950 Monster (水题)

    Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a k ...

  3. HDU 4813 Hard Code 水题

    Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  4. HDU 4593 H - Robot 水题

    H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.act ...

  5. HDOJ/HDU 2560 Buildings(嗯~水题)

    Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...

  6. HDOJ(HDU) 1859 最小长方形(水题、、)

    Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内 ...

  7. HDU - 1716 排列2 水题

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  8. HDU—2021-发工资咯(水题,有点贪心的思想)

    作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵  但是对于学校财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡老师最近就在考虑一个问题:如果每 ...

  9. hdu 5753 Permutation Bo 水题

    Permutation Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

随机推荐

  1. python三:循环语句练习--小白博客

    # 打印0-10去掉5 count = - : count += : continue print(count) # 打印0-10的偶数 count = : print(count) count+= ...

  2. Spectral Bounds for Sparse PCA: Exact and Greedy Algorithms[贪婪算法选特征]

    目录 概括 Sparse PCA Formulation 非常普遍的问题 Optimality Conditions Eigenvalue Bounds 算法 代码 概括 这篇论文,不像以往的那些论文 ...

  3. import导入模块,==和is,浅拷贝和深拷贝,进制转换,位运算,私有化,property装饰器

    '''import导入模块'''import sysprint(sys.path) sys.path.append('D://ASoft/Python/PycharmProjects')import ...

  4. Shell脚本命令图片

    查看相关文档:shell脚本1  shell脚本2

  5. CMMI摘要

    CMMI_百度百科https://baike.baidu.com/item/CMMI CMMI分为哪几个等级?CMMI等级介绍_百度经验https://jingyan.baidu.com/articl ...

  6. 从零开始搭建VUE项目

    前言: 此样板面向大型,严肃的项目,并假定您对Webpack和vue-loader有些熟悉. 请务必阅读vue-loader的常见工作流配方的文档. 如果您只想尝试vue-loader或者鞭打一个快速 ...

  7. (三)类数组对象 NamedNodeMap简单介绍

    Ele.attrbutes将返回一个NamedNodeMap对象,即NamedNodeMap存储的是元素的“特性Attribute”集合.而集合中的每一个元素,都是Attr类型的对象. html: & ...

  8. 通用模块设计UMD

    https://leohxj.gitbooks.io/front-end-database/content/javascript-modules/about-umd.html UMD(universa ...

  9. springmvc配置文件

    1 springMVC的配置文件路径问题 https://www.cnblogs.com/ysloong/p/6071450.html

  10. Dom4j解析

    dom4j-1.6.1.jar, 这个包提供了xml解析相关的方法. 这里做一个记录,微信公众号里需要对HttpServletRequest做解析,实际上也可以用dom4j提供的方法进行解析转换. 这 ...