80pts求调
查看原帖
80pts求调
937183
Awatesolo楼主2025/7/19 10:27

人都调傻了

思路是把关键点复制一份换连边后跑dij

玄2关

/**
 *
 *    ┏┓   ┏┓
 *   ┏┛┻━━━┛┻┓
 *   ┃       ┃
 *   ┃   ━   ┃
 *   ┃ ┳┛ ┗┳ ┃
 *   ┃       ┃
 *   ┃   ┻   ┃
 *   ┃       ┃
 *   ┗━┓   ┏━┛Code is far away from bug with the animal protecting
 *     ┃   ┃    神兽保佑,代码无bug
 *     ┃   ┃
 *     ┃   ┗━━━┓
 *     ┃      ┣┓
 *     ┃     ┏┛
 *     ┗┓┓┏━┳┓┏┛
 *      ┃┫┫ ┃┫┫
 *      ┗┻┛ ┗┻┛
 *
 */
#include<bits/stdc++.h>
#define int long long
#define pi pair<int,pair<int,int>>
using namespace std;
int n,m,k;
template<typename T>
inline void read(T &x) {
    x = 0;
    register char c = getchar();
    register short f = 1;
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    x *= f;
}
template <typename T, typename... Args>
inline void read(T &x, Args &...temps)
{
	read(x), read(temps...);
}
const int N=5000005;
struct nod{
	int x,y,v;
	int nxt;
};
void write(int x) {
	static int sta[35];
	int top = 0;
	do {
		sta[top++] = x % 10;
		x /= 10;
	} while (x);
	while (top) putchar(sta[--top] + '0');
}

bool cmp(pair<int,int> x,pair<int,int> y){
	return x.first<y.first;
}
int d[N];
int vis[N];
vector<int>g[N],c[N];	
vector<int>sp;
nod q[N];
bool bl[N];
void dij(int s){
	for(int i=1;i<=3*n+3;i++) d[i]=1e18;
	d[s]=0;
	for(int i=1;i<=3*n+3;i++) vis[i]=0;
	priority_queue<pi,vector<pi>,greater<pi>>q;
	pi fr;
	fr.first=0;
	fr.second.first=s;
	fr.second.second=0;
	q.push(fr);
	while(!q.empty()){
		pi tmp=q.top();
		q.pop();
		int x=tmp.second.first;
		if(vis[x]) continue;
		vis[x]=1;
		for(int i=0;i<g[x].size();i++){
			int y=g[x][i],j=c[x][i];
			if(y-n-3==tmp.second.second){
				continue;
			}			
			if(d[y]>d[x]+j){
				d[y]=d[x]+j;
				if(!vis[y]){
					pi nx;
					nx.first=d[y];
					nx.second.first=y;
					if(bl[x]){
						nx.second.second=x;
					}
					else nx.second.second=tmp.second.second;
					q.push(nx);
				}
			}
		}
	}	
}
void solve(){
	read(n,m,k);
	for(int i=1;i<=3*n+3;i++){
	//	fill(g[i].begin(),g[i].end(),0);
	//	fill(c[i].begin(),c[i].end(),0);	
		g[i].clear();
		c[i].clear();	
		bl[i]=0;		
		q[i].x=0;
		q[i].y=0;
		q[i].v=0;	
		q[i].nxt=0;	
	}
	//fill(sp.begin(),sp.end(),0);
	for(int i=1;i<=m;i++) {
		read(q[i].x,q[i].y,q[i].v);
		if(q[i].x==q[i].y) q[i].v=1e18;
	}
//	fill(sp.begin(),sp.end(),0);
	sp.clear();
	sp.push_back(0);
	for(int i=1;i<=k;i++){
		int x;
		read(x);
		sp.push_back(x);
		bl[x]=1;
	}
	for(int i=1;i<=m;i++){
		if(bl[q[i].y]==0){
	//		cout<<"St";
			g[q[i].x].push_back(q[i].y);
			c[q[i].x].push_back(q[i].v);
//			cout<<"Ed";
		}
		else{
	//		cout<<"St";			
			g[q[i].x].push_back(q[i].y+n+3);
			c[q[i].x].push_back(q[i].v);
	//		cout<<"Ed";			
		}
	}
	
	for(int i=1;i<=k;i++){
	//	cout<<1;
		g[n+1].push_back(sp[i]);
		c[n+1].push_back(0);
		g[sp[i]+n+3].push_back(n+2);
		c[sp[i]+n+3].push_back(0);
	}
	dij(n+1);
//	for(int i=1;i<=2*n;i++){
//		cout<<d[i]<<' ';
//	}
	cout<<d[n+2]<<'\n';
}
signed main(){
	int T;
	read(T);
	while(T--){
		solve();
	}
	return 0;
}

2025/7/19 10:27
加载中...