萌新95分代码求调
查看原帖
萌新95分代码求调
983532
Souki_楼主2024/10/19 15:33

rt,只有95分

请求各位大佬帮忙看一下(

#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<pair<int, int> > awa[114514];
int a[11451][114];
int dp[11451][114];
int maxn=1145141919810;
struct node 
{
    int u, i, a;
    bool operator<(const node &rhs) const 
	{
        return a > rhs.a;
    }
};
priority_queue<node> q;
signed main() 
{
    int n,m,cdf;
    cin>>n>>m>>cdf;
    while (m--) 
	{
        int u, v, w;
        cin>>u>>v>>w;
        awa[u].push_back({v, w});
    }
    memset(a, 1145141919810 , sizeof (a));
    q.push({1, 0, a[1][0] = 0});
    while (q.size()) 
	{
        int u = q.top().u, i = q.top().i;
        q.pop();
        if (dp[u][i]) 
        {
        	continue;
		}
        dp[u][i] = 1;
        for ( auto [v, w] : awa[u] ) 
		{
            int t = a[u][i], j = (i + 1) % cdf;
            if (t < w) 
            {
            	t += (w - t + cdf - 1) / cdf * cdf;
			}
            if (a[v][j] > t + 1) 
            {
            	q.push({v, j, a[v][j] = t + 1});
			}
        }
    }
    if (a[n][0] == maxn)
    {
    	cout<<-1;
    	return 0;
	}
    cout<<a[n][0];
    return 0;
}
2024/10/19 15:33
加载中...