【Edu49 1027D】 Mouse Hunt DFS 环】的更多相关文章

1027D. Mouse Hunt:http://codeforces.com/contest/1027/problem/D 题意: 有n个房间,每个房间放置捕鼠器的费用是不同的,已知老鼠在一个房间x,那么他一定会在下一秒到一个特定的房间a[x].老鼠一开始可能在任意一个房间,问最少需要多少的费用,使得一定能捉到老鼠. 思路: 这道题要在每个环上找一个费用最小的点,放置捕鼠器,进入环的那些点是不用放捕鼠器的.如何在dfs中找到环,并找到最小的点?在dfs中,如果发现下一个点已经走过,就说明遇到环…
<题目链接> 题目大意: 有n个房间,每个房间都会有一只老鼠.处于第i个房间的老鼠可以逃窜到第ai个房间中.现在要清理掉所有的老鼠,而在第i个房间中防止老鼠夹的花费是ci,问你消灭掉所有老鼠的最少花费. 解题分析: 首先就是要注意老鼠的逃生路线为强连通分量的情况,毫无疑问,这种情况就是在那个强连通分量中的代价最小的房间安装老鼠夹(因为根据老鼠的流通性,只需要在连通分量中安装一个老鼠夹就能捕获所有的老鼠),所以我们先用Tarjan对这些房间进行缩点.然后我们只需要将那些出度为0的强连通分量的代价…
题目描述: Mouse Hunt time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Medicine faculty of Berland State University has just finished their admission campaign. As usual, about 80%of applicants a…
Mouse Hunt 给定一个n个点的图,每个点有权值\(c_i\),并且只有一条出边.现在你要在一些点上打标记,使得从任何一个点出发最终都会经过有标记的点.求标记点的权值和最小值. 就是找环啊!拓扑排序啊! #include <cstdio> #include <algorithm> using namespace std; const int maxn=2e5+5; int n, c[maxn], a[maxn], in[maxn], vis[maxn]; int q[maxn…
Mouse Hunt time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Medicine faculty of Berland State University has just finished their admission campaign. As usual, about 80%80% of applicants are…
Medicine faculty of Berland State University has just finished their admission campaign. As usual, about 80%80% of applicants are girls and majority of them are going to live in the university dormitory for the next 44 (hopefully) years. The dormitor…
题意:给定n个房间,有一只老鼠可能从其中的任意一个出现, 在第i个房间设置捕鼠夹的代价是a[i],若老鼠当前在i号房间则下一秒会移动到b[i]号, 问一定能抓住老鼠的最小的总代价 n<=2e5,a[i]<=1e4 思路:tarjan缩点(环)之后找到所有出度为0的分量,找到分量中最小的a[i],将a[i]加到ans中 #include<cstdio> #include<cstring> #include<string> #include<cmath&g…
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 先求出来强连通分量. 每个联通分量里面,显然在联通块的尽头(没有出度)放一个捕鼠夹就ok了 [代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long #define rep1(i,a,b) for (int i = a;i <…
 Problem 1920 Left Mouse Button Accept: 385    Submit: 719 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Mine sweeper is a very popular small game in Windows operating system. The object of the game is to find mines, and mark…
这道题原本写了一个很复杂的DFS,然后陷入绝望的调试. 看了一下题解发现自己完全想复杂了. 这里大概就是补充一些题解没有详细解释的代码吧... (小声BB)现在最优解rank4(话说$O2$负优化什么鬼啊) read(n); ;i<=n;++i)read(c[i]); ;i<=n;++i){ read(a[i]); if(a[i]==i){ vis[i]=; ans+=c[i]; } } ;i<=n;++i){ if(vis[i])continue; for(register int j…