题目链接

  • 题意:

    给定n个点,每一个点有一个权值的有向图。如今须要选定一些点,使得这些点权值和最小。且满足:假设i能到达j且j能到达i,那么i、j能够仅仅选一个
  • 分析:

    强联通模板题

  1. //使用时仅仅更新G完毕构图
  2. //scc_cnt从1開始计数
  3.  
  4. //pre[]表示点在DFS树中的先序时间戳
  5. //lowlink[]表示当前点和后代能追溯到的最早祖先的pre值
  6. //sccno[]表示点所在的双连通分量编号
  7. //vector<int> G保存每一个点相邻的下一个点序号
  8. //stack<Edge> S是算法用到的栈
  9. const int MAXV = 310000;
  10.  
  11. vector<int> G[MAXV];
  12. int pre[MAXV], lowlink[MAXV], sccno[MAXV], dfs_clock, scc_cnt;
  13. stack<int> S;
  14.  
  15. void init(int n)
  16. {
  17. REP(i, n) G[i].clear();
  18. }
  19.  
  20. void dfs(int u)
  21. {
  22. pre[u] = lowlink[u] = ++dfs_clock;
  23. S.push(u);
  24. for(int i = 0; i < G[u].size(); i++)
  25. {
  26. int v = G[u][i];
  27. if(!pre[v])
  28. {
  29. dfs(v);
  30. lowlink[u] = min(lowlink[u], lowlink[v]);
  31. }
  32. else if(!sccno[v])
  33. {
  34. lowlink[u] = min(lowlink[u], pre[v]);
  35. }
  36. }
  37. if(lowlink[u] == pre[u])
  38. {
  39. scc_cnt++;
  40. for(;;)
  41. {
  42. int x = S.top();
  43. S.pop();
  44. sccno[x] = scc_cnt;
  45. if(x == u) break;
  46. }
  47. }
  48. }
  49.  
  50. void find_scc(int n)
  51. {
  52. dfs_clock = scc_cnt = 0;
  53. memset(sccno, 0, sizeof(sccno));
  54. memset(pre, 0, sizeof(pre));
  55. for(int i = 0; i < n; i++)
  56. if(!pre[i]) dfs(i);
  57. };
  58.  
  59. int cost[MAXV];
  60. vector<int> vt[MAXV];
  61. int Min[MAXV];
  62.  
  63. int main()
  64. {
  65. // freopen("in.txt", "r", stdin);
  66. int n, e, a, b;
  67. while (~RI(n))
  68. {
  69. init(n);
  70. REP(i, MAXV) vt[i].clear();
  71. CLR(Min, INF);
  72.  
  73. REP(i, n) RI(cost[i]);
  74. RI(e);
  75. REP(i, e)
  76. {
  77. RII(a, b); a--; b--;
  78. G[a].push_back(b);
  79. }
  80. find_scc(n);
  81.  
  82. REP(i, n)
  83. {
  84. int no = sccno[i];
  85. vt[no].push_back(i);
  86. Min[no] = min(Min[no], cost[i]);
  87. }
  88. LL v = 0, ans = 1;
  89. REP(i, MAXV)
  90. {
  91. if (vt[i].size() > 0)
  92. {
  93. int cnt = 0;
  94. REP(j, vt[i].size())
  95. {
  96. if (cost[vt[i][j]] == Min[i]) cnt++;
  97. }
  98. ans *= cnt;
  99. ans %= MOD;
  100. v += Min[i];
  101. }
  102. }
  103. cout << v << ' ' << ans << endl;
  104. }
  105. return 0;
  106. }

Codeforces Round #244 (Div. 2)——Checkposts的更多相关文章

  1. Codeforces Round #244 (Div. 2)D (后缀自己主动机)

    Codeforces Round #244 (Div. 2)D (后缀自己主动机) (标号为0的节点一定是null节点,不管怎样都不能拿来用,切记切记,以后不能再错了) 这题用后缀自己主动机的话,对后 ...

  2. Codeforces Round #244 (Div. 2) C. Checkposts (tarjan 强连通分量)

    题目:http://codeforces.com/problemset/problem/427/C 题意:给你n座城市,m条有向道路,然后有一个机制,你在某一个城市设置检查点,那么被设置的检查点受保护 ...

  3. Codeforces Round #244 (Div. 2)

    今天是水题集啊.... A. Police Recruits time limit per test 1 second memory limit per test 256 megabytes inpu ...

  4. Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq

    B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...

  5. Codeforces Round #244 (Div. 2) B. Prison Transfer

    题目是选出c个连续的囚犯,而且囚犯的级别不能大于t #include <iostream> using namespace std; int main(){ int n,t,c; cin ...

  6. Codeforces Round #244 (Div. 2) A. Police Recruits

    题目的意思就是找出未能及时处理的犯罪数, #include <iostream> using namespace std; int main(){ int n; cin >> ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. noi 题库1.7字符串 第16至20题

    16:忽略大小写的字符串比较 一般我们用strcmp可比较两个字符串的大小,比较方法为对两个字符串从前往后逐个字符相比较(按ASCII码值大小比较),直到出现不同的字符或遇到'\0'为止.如果全部字符 ...

  2. [SHOI2009] 交通网络

    简单最短路计数. #include<bits/stdc++.h> #define ll long long using namespace std; #define D double co ...

  3. 【kmp算法】模板

    void GetFail(char P[],int __next[])//__next[i]表示s[0]~s[i-1]的前缀中,最大长度相等的前后缀是多少 { __next[0]=-1; int le ...

  4. FireDac Pooling

    1.建立FDManager的ConnectionDef.并设置此Pooling为True. 2.建立Thread类进行多个FDConnection连接DB. 3.本列是oracle远程数据.如下图: ...

  5. 输入格式MultipleInput

    MultipleInput输入格式允许一个job的输入为多个文件夹下的文件(也就是多路径输入),并且不同文件夹下的文件可以实现不同的map逻辑,不过貌似必须使用相同的reduce逻辑. http:// ...

  6. [转]从此爱上iOS Autolayout

    原文地址 这篇不是autolayout教程,只是autolayout动员文章和经验之谈,在本文第五节友情链接和推荐中,我将附上足够大家熟练使用autolayout的教程.这篇文章两个月前就想写下来,但 ...

  7. 生成随机位数的UUID

    1,生成UUID package com.jeeplus.common.utils; import java.util.UUID; /** * 生成唯一的UUID * * @author songya ...

  8. 动态OSPF配置路由表

    动态ospf设置路由表 以Rourer1为例子 (1)首先设置路由器端口ip Router(config)#inter f0/0 Router(config-if)#ip add 192.168.1. ...

  9. ORMLite整合SQLCipher

    Android数据库加密,目前就是SQLCipher对SQLite整体加密,微信也是使用这种方式.开源,且支持很多平台. SQLCipher虽说开源了,但是编译好的jar和so文件,还是要收费的. 但 ...

  10. 规约模式Specification Pattern

    什么是规约模式 规约模式允许我们将一小块领域知识封装到一个单元中,即规约,然后可以在code base中对其进行复用. 它可以用来解决在查询中泛滥着GetBySomething方法的问题,以及对查询条 ...