思路:
经典题 不解释
找到最小的数mn
所有都是在mod mn的意义下 搞得
i->(i+a[i])%mn 边权为a[i]
//By SiriusRen#include#include #include #include using namespace std;typedef long long ll;const int N=500000*13,inf=0x3f3f3f3f;int n,first[N],next[N],v[N],tot,minn=inf,a[15],vis[N];ll BMin,BMax,w[N],dis[N],ans;void add(int x,int y,int z){w[tot]=z,v[tot]=y,next[tot]=first[x],first[x]=tot++;}struct Node{ int now,dis;}st,jy;bool operator<(Node a,Node b){ return a.dis>b.dis;}priority_queue pq;int main(){ memset(first,-1,sizeof(first)); memset(dis,0x3f,sizeof(dis)); scanf("%d%lld%lld",&n,&BMin,&BMax); for(int i=1;i<=n;i++)scanf("%d",&a[i]),minn=min(minn,a[i]); dis[0]=0; for(int i=1;i<=n;i++) for(int j=0;j dis[t.now]+w[i]) dis[v[i]]=dis[t.now]+w[i], jy.now=v[i],jy.dis=dis[v[i]],pq.push(jy); }BMin--; for(int i=0;i