1 条题解

  • 1
    @ 2021-11-6 15:53:44
    /*****************************************
    备注:
    ******************************************/
    #include <queue>
    #include <stdio.h>
    #include <iostream>
    #include <string.h>
    #include <vector>
    using namespace std;
    const int N = 10000010;
    const int M = 1000010;
    #define pa pair<int , int>
    int read()
    {
    	int ww=0,cc=1; 
    	char ch=getchar();
    	while (ch<'0' || ch>'9')
    	{
    		if (ch=='-') 
    			cc=-1;
    		ch=getchar();
    	}
    	while (ch>='0' && ch<='9')
    		ww=ww*10+ch-'0',ch=getchar();
    	return ww*cc;
    }
    struct Edge
    {
        int to , w , ne;
    }e[N];
    int head[M] ,dis[M] ,T,rxa,rxc,rya,ryc,rp,n,m,idx=0;
    // bool vis[M];
    void add(int x, int y , int z)
    {
    	e[++idx].to = y;
    	e[idx].w    = z;
    	e[idx].ne   = head[x];
    	head[x]	    = idx; 
    }
    void dijkstra()
    {
    	priority_queue<pa,vector<pa>,greater<pa> > p;
    	dis[1] = 0;
    	p.push(make_pair(0,1));
    	int id , k, i;
    	while(!p.empty())
    	{
    		k = p.top().first;
    		id = p.top().second;
    		p.pop();
    		if(dis[id] != k )
    			continue;
    
    		// vis[id] = true;
    		for( i = head[id] ; i ; i = e[i].ne)
    		{
    			if(dis[ e[i].to ] > k + e[i].w)
    			{
    				dis[e[i].to] = k + e[i].w;
    				p.push( make_pair(  dis[e[i].to],e[i].to));
    			}
    		}
    	}
    	printf("%d\n",dis[n]);
    }
    int main()
    {
    	memset(dis ,0x3f , sizeof(dis));
    	n = read() , m = read();
    	int x,y,z,a,b;
    	x=  y = z = 0;
    	T = read() ,rxa = read() , rxc = read() , 
    	rya = read() , ryc = read() , rp = read();
    	for(int i =0 ; i < T ; ++i)
    	{
    		  x=(x*rxa+rxc)%rp;
    		  y=(y*rya+ryc)%rp;
    		  a=min(x%n+1,y%n+1);
    		  b=max(y%n+1,y%n+1);
    		  add(a,b,100000000 - 100*a);
    	}
    	for(int i = T; i < m ;++i)
    	{
    		x = read() ,y = read() , z = read();
    		add(x,y,z);
    	}
    	dijkstra();
    	return 0;
    }
    
    
    
    
    • 1

    信息

    ID
    1343
    时间
    12000ms
    内存
    512MiB
    难度
    8
    标签
    递交数
    203
    已通过
    33
    上传者