-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path427C.cpp
128 lines (114 loc) · 2.42 KB
/
427C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 1000000007
#define exit return 0
#define inf 1000000000
#define exit return 0
#define PS system("pause")
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define SZ(x) ((int)x.size())
#define MX(a,b)a>b?a:b
const double eps = 1e-10;
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define ll long long
int n,a,b,k;
int so,in;
int allin,games;
const int N = 200007;
//f[i] - number of towers when i know
// that i have r red blocks
//heigh is H
int r,g;
int f[N];
vector<int>gr[N];
int tin[N],comps,comp[N],timer, stck[N],sz,low[N],isin[N],cost[N];
void tarjan(int v){
low[v] = tin[v] = ++timer;
stck[sz++] = v;
isin[v] = 1;
for(int i=0; i < gr[v].size(); i++){
int to = gr[v][i];
if(tin[to] == -1){
tarjan(to);
//update
low [v] = min(low[v],low[to]);
}else if(isin[to]){
low [v] = min(low[v],tin[to]);
}
}
if(low[v] == tin[v]){
int y = -1;
comps++;
do{
y = stck[--sz];
comp[y] = comps;
isin[y] = 0;
}while(y!=v);
}
}
void go(){
memset(tin,-1,sizeof(tin));
comps = timer = sz = 0;
rep(i,n){
if(tin[i] == -1)tarjan(i);
}
}
int mn[N],cnt[N];
int main(){
scanf("%d ",&n);
rep(i,n){
scanf("%d",&cost[i]);
}
int m;
scanf("%d ",&m);
while(m--){
scanf("%d %d",&a,&b);
a--,b--;
gr[a].push_back(b);
}
go();
//cout<<comps<<endl;
for(int i=1;i<=comps;i++)mn[i] = (2123123123);
rep(i,n){
int cc = comp[i];
int ww = cost[i];
if(mn[cc] > ww){
mn[cc] = ww;
cnt[cc] = 1;
}else if(mn[cc]==ww){
cnt[cc] += 1;
}
}
ll aa = 0, bb = 1;
//cout<<comps;
for(int i=1;i<=comps;i++) {
aa += mn[i];
bb *= (cnt[i]);
bb %= MOD;
}
printf("%I64d %I64d",aa,bb);
}