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. JavaSwing输入对话框,点击取消抛出异常的解决方法

    在做产品管理系统的时候,遇到一个问题: 在得到一个输入框对话框的时候 String textPrice = JOptionPane.showInputDialog("请输入要调整的价格增(减 ...

  2. 栗染-Myeclispe连接SQL Server数据库

    第一步,在SQL server方面 这里是以身份验证登录. 这里我是建了一个hw的数据库,其他没啥说的. 第二步,最主要的一部分 因为第一次连接SQL Server数据库,所以就不知道还有这一步.不然 ...

  3. 10.16NOIP模拟赛

    /* 我是一个大sb */ #include<iostream> #include<cstdio> #include<cstring> #include<qu ...

  4. Hexo 添加Live2D看板娘

    title: Hexo 添加 Live2D看板娘 二次元什么的最喜欢了[大好きです] 准备 项目地址 live2d模型 部分模型预览 开始 首先进入Hexo博客根目录安装live2d插件 $ npm ...

  5. php做APP接口开发,接口的安全性

    1.当用户登录APP时,使用https协议调用后台相关接口,服务器端根据用户名和密码时生成一个access_key,并将access_key保存在session(或者保存在redis)中,将生成的ac ...

  6. [ZJOI2006]Book书架

    Description Sally有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号.Sally在看书的时候,每次取出一本书,看完后放回书柜 ...

  7. Storm概念学习系列之storm的优化

    不多说,直接上干货!

  8. dubbo与springmvc的简单使用

    什么是Dubbo? dubbo是阿里巴巴公司开源的高性能优秀服务框架,通过高性能的RPC(远程服务调用)实现服务的输入输出功能,可以与spring框架无缝整合: 传统的架构所有的模块都在一台服务器上, ...

  9. 两年,VMware又重回巅峰?

    两年前,被公有云和容器打的焦头烂额的VMware一度被众多业界人士看衰,营收.股价双双下滑.然而,仅仅经过短短两年时间,VMware已经和AWS,IBM.微软.Rackspace等众多公有云厂商成为合 ...

  10. SVN的三种merge方式【转】

    SVN的merge操作是为了保证主干(trunk)和分支(branch)同步,merge方式有: 1.Merge a range of revisions(合并一个范围的版本) 2.Reintegra ...