#include<bits/stdc++.h>
#define int long long
using namespace std;
double dis(double x_1,double y_1,double x_2,double y_2) {
return (x_1 - x_2) * (x_1 - x_2) + (y_1 - y_2) * (y_1 - y_2);
}
int head[405],nex[500005],cnt;
double x[405],y[405],T[405];
struct edge{
int to;
double w;
}node[500005];
double t;
int s,a,b;
void add(int p1,int p2,double w) {
nex[++cnt] = head[p1];
head[p1] = cnt;
node[cnt].to = p2;
node[cnt].w = w;
}
struct point{
int id;
double w;
friend bool operator <(point x_1,point y_1) {
return x_1.w > y_1.w;
}
};
priority_queue<point>p;
double ans[405];
signed main() {
ios::sync_with_stdio(false);//取消输入输出流和stdio流的同步
cin.tie(0);//解除cin和cout的绑定
int n;
cin>>n;
while(n--) {
//预处理
cnt = 0;
for(int i = 0;i <= 400;i++) ans[i] = 10000000.0,head[i] = 0,x[i] = 0,y[i] = 0,T[i] = 0;
for(int i = 0;i <= 500000;i++) nex[i] = 0,node[i].to = 0,node[i].w = 0;
//输入
cin>>s>>t>>a>>b;
for(int i = 0;i < s;i++) {
cin>>x[i * 4 + 1]>>y[i * 4 + 1];
cin>>x[i * 4 + 2]>>y[i * 4 + 2];
cin>>x[i * 4 + 3]>>y[i * 4 + 3];
cin>>T[i];
double dis1 = dis(x[i * 4 + 2],y[i * 4 + 2],x[i * 4 + 3],y[i * 4 + 3]);
double dis2 = dis(x[i * 4 + 1],y[i * 4 + 1],x[i * 4 + 3],y[i * 4 + 3]);
double dis3 = dis(x[i * 4 + 1],y[i * 4 + 1],x[i * 4 + 2],y[i * 4 + 2]);
// cout<<dis1<<" "<<dis2<<" "<<dis3<<endl;
if(dis1 + dis2 == dis3) {
x[i * 4] = x[i * 4 + 1] + x[i * 4 + 2] - x[i * 4 + 3];
y[i * 4] = y[i * 4 + 1] + y[i * 4 + 2] - y[i * 4 + 3];
}
if(dis1 + dis3 == dis2) {
x[i * 4] = x[i * 4 + 1] + x[i * 4 + 3] - x[i * 4 + 2];
y[i * 4] = y[i * 4 + 1] + y[i * 4 + 3] - y[i * 4 + 2];
}
if(dis2 + dis3 == dis1) {
x[i * 4] = x[i * 4 + 2] + x[i * 4 + 3] - x[i * 4 + 1];
y[i * 4] = y[i * 4 + 2] + y[i * 4 + 3] - y[i * 4 + 1];
}
}
for(int i = 0;i <= s * 4 - 2;i++) {
// cout<<x[i]<<" "<<y[i]<<endl;
for(int j = i + 1;j <= s * 4 - 1;j++) {
double d = sqrt(dis(x[i],y[i],x[j],y[j]));
//printf("%lld %lld %.1lf\n",i,j,d);
if(i / 4 == j / 4) add(i,j,d * T[i / 4]),add(j,i,d * T[i / 4]);
else add(i,j,d * t),add(j,i,d * t);
}
}
point start;
start.w = 0;
for(int i = 0;i < 4;i++) start.id = i,p.push(start);
//dij
while(!p.empty()) {
start = p.top();
p.pop();
if(ans[start.id] != 10000000.0) continue;
ans[start.id] = start.w;
//printf("%lld %.1lf:\n",start.id,ans[start.id]);
for(int i = head[start.id];i;i = nex[i]) {
//printf("%lld %.1lf %.1lf\n",node[i].to,node[i].w,ans[node[i].to]);
if(ans[node[i].to] > ans[start.id] + node[i].w) {
point new_point;
new_point.id = node[i].to;
new_point.w = ans[start.id] + node[i].w;
p.push(new_point);
//printf("__________\n");
}
}
}
double min_ans = 10000000.0;
for(int i = 4 * s - 4;i < 4 * s;i++) {
if(min_ans > ans[i]) min_ans = ans[i];
}
printf("%.1lf\n",min_ans);
}
return 0;
}
第4个点wa了,input:
1
10 10 1 2
27 27 194 105 194 27 10
366 290 381 290 366 305 10
80 158 196 245 196 158 1
289 154 358 154 358 86 2
17 284 84 350 84 284 1
175 289 292 289 175 362 3
450 371 420 371 420 32 2
241 29 270 29 270 43 4
251 182 347 270 251 270 5
347 341 410 341 347 369 1
output:
1885.0