# Summer Holiday

Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2371    Accepted Submission(s): 1111

Problem Description
To see a World in a Grain of Sand
And a Heaven in a Wild Flower,
Hold Infinity in the palm of your hand
And Eternity in an hour.
—— William Blake

Input

Output

Sample Input
12 16 2 2 2 2 2 2 2 2 2 2 2 2 1 3 3 2 2 1 3 4 2 4 3 5 5 4 4 6 6 4 7 4 7 12 7 8 8 7 8 9 10 9 11 10

Sample Output
3 6

Author

Source

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<vector>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=100010;
int MIN(int a,int b){
return a<b?a:b;
}
int value[maxn];
int scc_cnt,dfs_clock;
int sccno[maxn];
int dfn[maxn];
int low[maxn];
int num[maxn];
int in[maxn];
int out[maxn];
bool instack[maxn];
stack<int>S;
vector<int>scc[maxn];
vector<int>G[maxn];
struct Node{
int from,to,next;
}A[maxn];
void init(){
memset(low,0,sizeof(low));
memset(dfn,0,sizeof(dfn));
memset(instack,false,sizeof(instack));
memset(sccno,0,sizeof(sccno));
memset(in,0,sizeof(in));
memset(out,0,sizeof(out));
memset(value,0x3f,sizeof(value));
scc_cnt=dfs_clock=0;
}
void tarjan(int u,int pre){
low[u]=dfn[u]=++dfs_clock;
S.push(u);instack[u]=true;
int v;
v=A[k].to;
if(!dfn[v]){
tarjan(v,u);
low[u]=MIN(low[u],low[v]);
}
else if(instack[v]){
low[u]=MIN(low[u],dfn[v]);
}
}
if(low[u]==dfn[u]){
scc_cnt++;scc[scc_cnt].clear();
while(1){
v=S.top();S.pop();
instack[v]=false;
sccno[v]=scc_cnt;
G[scc_cnt].clear();
scc[scc_cnt].push_back(v);
value[scc_cnt]=MIN(value[scc_cnt],num[v]);
if(v==u)break;

}
}
}
void suodian(int m){
for(int i=0;i<m;++i){
int u=sccno[A[i].from];
int v=sccno[A[i].to];
if(u!=v){
G[u].push_back(v);
in[v]++;out[u]++;
}
}
}
int main()
{
int n,m,i,j,k;
while(scanf("%d%d",&n,&m)!=EOF){
init();
for(i=1;i<=n;++i){
scanf("%d",&num[i]);
}
int a,b;
for(i=0;i<m;++i){
scanf("%d%d",&a,&b);
A[i].from=a;
A[i].to=b;
}
for(i=1;i<=n;++i){
if(!dfn[i])tarjan(i,-1);
}
suodian(m);
int ans1=0,ans2=0;
for(i=1;i<=scc_cnt;++i){
if(in[i]==0){
ans1++;
ans2+=value[i];
}
}
printf("%d %d\n",ans1,ans2);
}
return 0;
}

#### hdu 1827 Summer Holiday（强连通分量+缩点）

2017-10-19 21:43:06

#### HDOJ 题目1827 Summer Holiday（强连通分量，缩点）

2015-02-09 00:50:24

#### 【强连通分量+缩点】 HDOJ 1827 Summer Holiday

2014-07-26 12:12:00

#### hdu 1827 Summer Holiday【Tarjan缩点】

2017-09-16 23:56:18

#### 【HDU】1827 Summer Holiday 强连通缩点

2014-07-06 12:52:47

#### hdoj-1827-Summer Holiday(scc+缩点)

2015-10-23 17:49:47

#### 不是图论 【tarjan求scc】+【缩点】

2017-04-30 14:39:40

#### poj--1236--Network of Schools（scc+缩点）

2016-01-12 15:27:15

#### hdoj2767Proving Equivalences【scc+缩点】

2015-11-20 21:21:33

#### poj2186Popular Cows【scc+缩点】

2015-11-19 11:45:08