# [图论训练]BZOJ 2118: 墨墨的等式 【最短路】

2 5 10
3 5

5

## HINT

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<algorithm>
#define maxn 500009
using namespace std;
typedef pair<long long,int> pii;
priority_queue<pii, vector<pii>, greater<pii> >q;
int value[10000005];
long long dist[maxn];
{
long long x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void add(int x,int y,int v)
{
point[now] = y;
value[now] = v;
}
void dijkstra(int s,int n)
{
for(int i=0;i<=n;i++)dist[i]=(long long)1e60;
dist[s] = 0;
int visit[maxn]={0};
q.push(make_pair(0,s));
while(!q.empty())
{
int u = q.top().second;
q.pop();
if(visit[u])continue;
visit[u] = 1;
for(int i = head[u];i;i=nex[i])
{
int k = point[i];
if(dist[u]+value[i]<dist[k])
{
dist[k] = dist[u] + value[i];
q.push(make_pair(dist[k],k));
}
}
}
}
int main()
{
long long amin,aj=1;
amin = a[1];
for(int i=2;i<=n;i++)
{
if(a[i]<amin)
{
amin=a[i];
aj=i;
}
}
//printf("amin=%d\n",amin);
for(int i=0;i<amin;i++)
{
for(int j=1;j<=n;j++)if(j!=aj)
{
}
}
dijkstra(0,amin);
//for(int i=0;i<amin;i++)printf("%d :  %lld\n",i,dist[i]);
for(int i=0;i<amin;i++)if(dist[i]<=bmax)
{
long long u = max(dist[i],(long long)bmin)-1;
long long l = u / amin, r = bmax / amin;
if(bmax % amin >= i)r++;
if(u % amin >= i)l++;
ans += r - l;
}
printf("%lld\n",ans);
return 0;
}

posted @ 2015-08-26 20:56  philippica  阅读(442)  评论(0编辑  收藏  举报