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. VS2015 razor 提示一闪而过

    出现的问题链接地址 https://social.microsoft.com/Forums/azure/zh-CN/ff308f71-c743-4f8c-b5e4-a7260c8b5f59/vs201 ...

  2. recast 生成navmesh主要流程

    参考:      critterai  http://www.critterai.org      recast & Detour https://github.com/recastnavig ...

  3. 略微讲讲最近的 webpack 该如何加快编译

    首先假设 基础的环境是有 creat-react-app 所创建的 即所有基础的loader,插件的 cache 都已经缓存了 在这种情况下想加速,真是很难 不过,有一个插件是可以观察 各个模块所花的 ...

  4. vs2017 + miniUI + dapper 添加、修改、删除、查询操作

    A.数据库表引用先前建立的company 公司信息表. B.建立文件: views > Home > Company.cshtml(新建文件) ,代码如下(直接复制即可) @{ Layou ...

  5. 洛谷P3383 【模板】线性筛素数 (埃拉托斯特尼筛法)

    题目描述 如题,给定一个范围N,你需要处理M个某数字是否为质数的询问(每个数字均在范围1-N内) 输入输出格式 输入格式: 第一行包含两个正整数N.M,分别表示查询的范围和查询的个数. 接下来M行每行 ...

  6. POJ 3608 旋转卡壳

    思路: 旋转卡壳应用 注意点&边  边&边  点&点 三种情况 //By SiriusRen #include <cmath> #include <cstdi ...

  7. 如何上传文件到 github

    1. 下载并安装 Git 2. 打开命令窗口:Git Bash Here 3. 在 github.coding 等上新建项目,并复制地址,如:https://git.coding.net/wangzh ...

  8. 网站开发综合技术 第一部分HTML 1.3.2表单

    <form id="" name="" method="post/get" action="负责处理的服务端"&g ...

  9. MySql数据查询中 left join 条件位置区别

    /*A 和 B 两张表都只有一个 ID 字段 比如A表的数据为 ID 1,2,3,4,5,6 B表的数据为 ID 1,2,3 判断 JOIN 查询时候条件在 ON 和 WHERE 时的区别 ON 和 ...

  10. jQuery学习笔记(2)-选择器的使用

    一.选择器是什么 有了jQuery的选择器,我们几乎可以获取页面上任意一个或一组对象 二.Dom对象和jQuery包装集 1.Dom对象 JavaScript中获取Dom对象的方式 <div i ...