Term Project

Time Limit: 3000ms
Memory Limit: 131072KB

This problem will be judged on UVALive. Original ID: 6511
64-bit integer IO format: %lld      Java class name: Main

 
 
解题:强连通分量 
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct arc{
int to,next;
arc(int x = ,int y = -){
to = x;
next = y;
}
}e[maxn*];
int head[maxn],dfn[maxn],low[maxn],belong[maxn],cnt[maxn];
int tot,clk,scc;
bool instack[maxn];
stack<int>stk;
void init(){
for(int i = tot = clk = scc = ; i < maxn; ++i){
head[i] = -;
dfn[i] = ;
cnt[i] = belong[i] = ;
instack[i] = false;
}
while(!stk.empty()) stk.pop();
}
void add(int u,int v){
e[tot] = arc(v,head[u]);
head[u] = tot++;
}
void tarjan(int u){
dfn[u] = low[u] = ++clk;
instack[u] = true;
stk.push(u);
for(int i = head[u]; ~i; i = e[i].next){
if(!dfn[e[i].to]){
tarjan(e[i].to);
low[u] = min(low[u],low[e[i].to]);
}else if(instack[e[i].to]) low[u] = min(low[u],dfn[e[i].to]);
}
if(low[u] == dfn[u]){
scc++;
int v;
do{
instack[v = stk.top()] = false;
belong[v] = scc;
stk.pop();
cnt[scc]++;
}while(v != u);
}
}
int main(){
int kase,n;
scanf("%d",&kase);
while(kase--){
init();
scanf("%d",&n);
int ret = ;
for(int i = ,tmp; i <= n; ++i){
scanf("%d",&tmp);
add(i,tmp);
ret += i == tmp;
}
for(int i = ; i <= n; ++i)
if(!dfn[i]) tarjan(i);
for(int i = ; i <= scc; ++i)
if(cnt[i] > ) ret += cnt[i];
printf("%d\n",n - ret);
}
return ;
}
 

UVALive 6511 Term Project的更多相关文章

  1. Tarjan UVALive 6511 Term Project

    题目传送门 /* 题意:第i个人选择第a[i]个人,问组成强联通分量(自己连自己也算)外还有多少零散的人 有向图强联通分量-Tarjan算法:在模板上加一个num数组,记录每个连通分量的点数,若超过1 ...

  2. (Your)((Term)((Project)))

    Description You have typed the report of your term project in your personal computer. There are seve ...

  3. POJ--1690 (Your)((Term)((Project)))(字符串处理)

    (Your)((Term)((Project))) Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3353 Accepted: ...

  4. POJ 1690 (Your)((Term)((Project)))

    (Your)((Term)((Project))) Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2912   Accept ...

  5. ZOJ 1423 (Your)((Term)((Project))) (模拟+数据结构)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=423 Sample Input 3(A-B + C) - (A+(B ...

  6. Storm(3) - Calculating Term Importance with Trident

    Creating a URL stream using a Twitter filter Start by creating the project directory and standard Ma ...

  7. Distributed Databases and Data Mining: Class timetable

    Course textbooks Text 1: M. T. Oszu and P. Valduriez, Principles of Distributed Database Systems, 2n ...

  8. 别人整理的DP大全(转)

    动态规划 动态规划 容易: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...

  9. dp题目列表

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

随机推荐

  1. ssh&amp;远程桌面连接工具finalshell

    无意间发现的一款工具,有兴趣的可以看看点我进入官网 百度云盘 链接:https://pan.baidu.com/s/1wMuGav64e2zV91QznBkvag 密码:zpyb软件特点直接搬运的官方 ...

  2. 394 Decode String 字符串解码

    给定一个经过编码的字符串,返回它解码后的字符串.编码规则为: k[encoded_string],表示其中方括号内部的 encoded_string 正好重复 k 次.注意 k 保证为正整数.你可以认 ...

  3. json常识

    转载网址:http://developer.51cto.com/art/201704/536386.htm   我们先来看一个JS中常见的JS对象序列化成JSON字符串的问题. 请问:以下JS对象通过 ...

  4. Spring.Net学习笔记(2)-依赖注入

    一.开发环境 操作系统:Win10 编译器:VS2013 framework版本:.net 4.5 Spring版本:1.3.1 二.涉及程序集 Spring.Core.dll Common.Logg ...

  5. outlook 2016 接收发送无法及时收下邮件,如何更改接收时间?

    1. 单击“文件” > “选项” > “高级” > “发送和接收”,单击”发送/接收“ 2. 组“所有账户”的设置 > 打勾“安排自动发送/接收的时间间隔为(V)” 1 分钟 ...

  6. Socket编程的简单实现

    关于socket编程的简单实现,主要分成客户端.服务端两个部分.实现如下: 1.服务端代码如下,注意:server端要优先于client端启动 2.client端代码,以及启动后客户端和服务端之间的简 ...

  7. windows2008 rs+sql 2008 下配置站点权限

    几点注意 Windows 2008 iis7.5  1 建立应用程序池 2 文件目录的权限加上 IIS AppPool\应用程序池名称 (找不到直接录入) 3 文件目录要给 IUser权限,不然出错. ...

  8. Java_数组1_16.5.12

    声明整型数组a: int[] a; 这时,只声明了变量a,还应该使用new运算符创建数组: int[] a=new int [100];(数组长度不要求是一个常量:new int[n]会创建一个长度为 ...

  9. node遍历给定目录下特定文件,内容合并到一个文件

    遍历目录用了fs.readdir这个异步方法,得到当前目录下所有的文件和目录的一个数组.然后判断: if文件,并且后缀符合设定的规则(本文例子是符合后缀ts,js)直接用同步方法写入, if目录,继续 ...

  10. 表格 —— 一个单元格插入多个tags

    <st #st [columns]="columns" [data]="data" [bordered]='true'> <ng-templa ...