UVA11770 - Lighting Away
题意:一个有向图,每对一个结点操作。就能够触发连锁反应,使得该结点及它直接或间接指向的点均获得标记,问至少须要操作多少个结点使得全部结点获得标记
思路:有向图的强连通分量。用Tarjan缩点之后找出入度为0的点的个数,即为答案。跟UVA11504一样的题目。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int MAXN = 10010;
const int MAXM = 100010; struct Edge{
int to, next;
}edge[MAXM]; int head[MAXN], tot;
int Low[MAXN], DFN[MAXN], Stack[MAXN], Belong[MAXN];
int Index, top;
int scc;
bool Instack[MAXN];
int num[MAXN], dg[MAXN];
int n, m; void init() {
tot = 0;
memset(head, -1, sizeof(head));
} void addedge(int u, int v) {
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++;
} void Tarjan(int u) {
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
for (int i = head[u]; i != -1; i = edge[i].next) {
v = edge[i].to;
if (!DFN[v]) {
Tarjan(v);
if (Low[u] > Low[v]) Low[u] = Low[v]; }
else if (Instack[v] && Low[u] > DFN[v])
Low[u] = DFN[v];
}
if (Low[u] == DFN[u]) {
scc++;
do {
v = Stack[--top];
Instack[v] = false;
Belong[v] = scc;
num[scc]++;
} while (v != u);
}
} void solve() {
memset(Low, 0, sizeof(Low));
memset(DFN, 0, sizeof(DFN));
memset(num, 0, sizeof(num));
memset(Belong, 0, sizeof(Belong));
memset(Stack, 0, sizeof(Stack));
memset(Instack, false, sizeof(Instack));
Index = scc = top = 0;
for (int i = 1; i <= n; i++)
if (!DFN[i])
Tarjan(i);
} int main() {
int cas, t = 1;
scanf("%d", &cas);
while (cas--) {
scanf("%d%d", &n, &m);
init();
int u, v;
for (int i = 0; i < m; i++) {
scanf("%d%d", &u, &v);
addedge(u, v);
}
solve(); memset(dg, 0, sizeof(dg));
for (int u = 1; u <= n; u++) {
for (int i = head[u]; i != -1; i = edge[i].next) {
int v = edge[i].to;
if (Belong[u] != Belong[v]) {
dg[Belong[v]]++;
}
}
}
int ans = 0;
for (int i = 1; i <= scc; i++) {
if (dg[i] == 0)
ans++;
}
printf("Case %d: %d\n", t++, ans);
}
return 0;
}
UVA11770 - Lighting Away的更多相关文章
- Vuforia结合Skyshop: Image-Based Lighting Tools & Shaders插件实现真实的光照效果
Skyshop: Image-Based Lighting Tools & Shaders 插件地址:https://www.assetstore.unity3d.com/en/#!/cont ...
- 球谐光照(Spherical Harmonics Lighting)及其应用-实验篇
简介 之前在一篇实时深度图优化的论文中看到球谐光照(Spherical Harmonics Lighting)的应用,在查阅了许许多多资料之后还是无法完全理解,我个人觉得如果之前对实时渲染技术不是很了 ...
- Direct3D学习笔记 - 浅析HDR Lighting Sample
一.HDR简介 HDR(High Dynamic Range,高动态范围)是一种图像后处理技术,是一种表达超过了显示器所能表现的亮度范围的图像映射技术.高动态范围技术能够很好地再现现实生活中丰富的亮度 ...
- Unity Shader——Writing Surface Shaders(2)——Custom Lighting models in Surface Shaders
Surface Shader中的自定义光照模型 当你在编写 Surface Shaders 时,是在描述一个表面的属性(反射颜色.法线……),而且光的交互过程是由一个光照模型来计算的.内建的光照模型有 ...
- 【Unity】13.2 通过Lighting Window设置相关参数
分类:Unity.C#.VS2015 创建日期:2016-05-19 一.简介 Unity 5.3.4的Lighting Window有3个选项卡:Object.Scene.Lightmaps. 二. ...
- Nvidia Anisotropic Lighting
http://http.download.nvidia.com/developer/SDK/Individual_Samples/DEMOS/Direct3D9/HLSL_Aniso.zip Anis ...
- [ZZ] 基于DirectX shader的Per-pixel lighting实现
这个特效需要用到DX11 UAV吗? http://blog.tianya.cn/blogger/post_show.asp?BlogID=510979&PostID=5665974 Intr ...
- MATLAB light material lighting
clf;[X,Y,Z]=sphere(40);colormap(jet)subplot(1,2,1),surf(X,Y,Z),axis off square,shading interplight(' ...
- 【线性结构上的动态规划】UVa 11400 - Lighting System Design
Problem F Lighting System Design Input: Standard Input Output: Standard Output You are given the tas ...
随机推荐
- 记账APP市场分析
文/欧小慧(简书作者)原文链接:http://www.jianshu.com/p/281fcdce3baa著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 一.市场环境 1.理财记账类用 ...
- 用js判断浏览器类型及设备
<!DOCTYPE html> <html> <head> <title>JS判断是什么设备是什么浏览器</title> <meta ...
- django 报错 no such table: auth_user
需要执行 python3 manage.py makemigrations python3 manage.py migrate 参考:http://arrayoverflow.com/question ...
- 【CF56E】Domino Principle(线性扫描,伪DP)
每块多米诺骨牌所在的位置设为x,每块多米诺骨牌高度为h.如果将x位置上的多米诺骨牌向右翻到,它就可以影响[x+1, x+h-1]范围内的所有多米诺骨牌,让他们也翻到,同时这些被翻到的多米诺骨牌还能影响 ...
- sublime text3 cssrem 快速px转rem插件
今天试验了下cssrem 在移动端如果需要px->rem非常方便 比较之前我自己用gulp提供的函数unit(70/@base,rem);转方便很多 1.git clone https://g ...
- ubuntu 为firefox 安装flash_player
1.下载安装包install_flash_player_11_linux.i386.tar.gz: 2.解压文件:$ tar -xvf install_flash_player_11_linux.i3 ...
- PHP 几个常用的正则表达式
记录几个PHP中比较常用的正则. , $max_len = 20){ if (empty($username)) { return false; } $match = '/^(?![0-9]+$)[\ ...
- AC日记——最大子树和 洛谷 P1122
题目描述 小明对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题.一天他早晨骑车去上课,路上见到一个老伯正在修剪花花草草,顿时想到了一个有关修剪花卉的问题.于是当日课后,小明 ...
- js-控制浏览器和移动端的后退按钮 . popstate
//控制浏览器和移动端的后退按钮 if (window.history && window.history.pushState) { $(window).on('popstate', ...
- Codechef Eugene and big number(矩阵快速幂)
题目链接 Eugene and big number 题目转化为 $f(n) = m * f(n - 1) + a$ $f(n + 1) = m * f(n) + a$ 两式相减得 $f(n + 1) ...