1 条题解

  • 0
    @ 2026-8-9 11:32:41
    #include<bits/stdc++.h>
    #define int long long
    #define mk make_pair
    #define PII pair<int,int>
    #define FOR(i,j,k) for(int i=(j);i<=(k);++i)
    #define ROF(i,j,k) for(int i=(j);i>=(k);--i)
    #define FOI(a,b) for(auto a : b)
    #define wh while
    #define inf 0x3f3f3f3f3f3f3f3f
    #define IOS ios::sync_with_stdio(false);
    #define snd second
    #define fst first
    #define pb push_back
    #define CI const int
    #define NP namespace
    using NP std;
    struct eg
    {
    	int v,mo,op;
    };
    int n,m,p;
    vector<eg> g[20005];
    int mc[20005];
    int d[20005][22];
    struct nd
    {
    	int u,l,di;
    	bool operator<(const nd& o)const
    	{
    		return di>o.di;
    	}
    };
    signed main(void)
    {
    	freopen("levelup.in","r",stdin);
    	freopen("levelup.out","w",stdout);
    	IOS
    	cin>>n>>m>>p;
    	FOR(i,1,m)
    	{
    		int u,v,mo,op;
    		cin>>u>>v>>mo>>op;
    		g[u].pb({v,mo,op});
    	}
    	FOR(i,1,20000)
    	{
    		mc[i]=inf;
    	}
    	FOR(i,1,p)
    	{
    		int po,c;
    		cin>>po>>c;
    		mc[po]=min(mc[po],c);
    	}
    	int st,ed;
    	cin>>st>>ed;
    	FOR(i,1,n)
    	{
    		FOR(j,0,21)
    		{
    			d[i][j]=inf;
    		}
    	}
    	priority_queue<nd> pq;
    	d[st][0]=0;
    	pq.push({st,0,0});
    	wh(!pq.empty())
    	{
    		nd cu=pq.top();
    		pq.pop();
    		int u=cu.u,l=cu.l,di=cu.di;
    		if(di>d[u][l])
    		{
    			continue;
    		}
    		if(l<21&&mc[u]!=inf)
    		{
    			if(d[u][l+1]>di+mc[u])
    			{
    				d[u][l+1]=di+mc[u];
    				pq.push({u,l+1,d[u][l+1]});
    			}
    		}
    		FOI(e,g[u])
    		{
    			int lv=(1LL<<l);
    			int w=(e.mo+lv-1)/lv;
    			int nl=(e.op==1)?0:l;
    			if(d[e.v][nl]>di+w)
    			{
    				d[e.v][nl]=di+w;
    				pq.push({e.v,nl,d[e.v][nl]});
    			}
    		}
    	}
    	int ans=inf;
    	FOR(j,0,21)
    	{
    		ans=min(ans,d[ed][j]);
    	}
    	if(ans==inf)
    	{
    		cout<<"Impossible!\n";
    	}
    	else
    	{
    		cout<<ans<<"\n";
    	}
    	return 0;
    }
    

    信息

    ID
    7134
    时间
    1000ms
    内存
    256MiB
    难度
    1
    标签
    (无)
    递交数
    2
    已通过
    2
    上传者