记录每个强连通分量中,最小值与最小值个数。
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e5+5,MOD=1e9+7;
int n,m,u,v,ans1,ans2;
int now,top,col,dfn[N],low[N],sta[N],color[N],minn[N],sum[N],a[N];
int cnt,head[N];
struct edge{int next,to;}e[N<<1];
inline void add(int u,int v)
{
cnt++;
e[cnt].next=head[u];
e[cnt].to=v;
head[u]=cnt;
}
void tarjan(int u)
{
dfn[u]=low[u]=++now;
sta[++top]=u;
for (register 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 (!color[e[i].to]) low[u]=min(low[u],low[e[i].to]);
}
if (dfn[u]==low[u])
{
col++;
bool jay=true;
while (jay)
{
if (sta[top]==u) jay=false;
color[sta[top]]=col;
if (a[sta[top]]<minn[col]) minn[col]=a[sta[top]],sum[col]=1;
else if (a[sta[top]]==minn[col]) sum[col]++;
top--;
if (!jay) break;
}
}
}
signed main(){
scanf("%lld",&n);
for (register int i=1; i<=n; ++i) scanf("%lld",&a[i]);
scanf("%lld",&m);
for (register int i=1; i<=m; ++i) scanf("%lld%lld",&u,&v),add(u,v);
memset(minn,60,sizeof(minn));
for (register int i=1; i<=n; ++i) if (!dfn[i]) tarjan(i);
ans2=1;
for (register int i=1; i<=col; ++i)
{
ans1+=minn[i];
ans2=(ans2*sum[i])%MOD;
}
printf("%lld %lld\n",ans1,ans2);
return 0;
}