rt,已知是最短路寄了,会RE,球球帮下忙
#include <bits/stdc++.h>
struct stack {
int the_stack[1001],sum=0;
inline int top() { return the_stack[sum-1]; }
inline int pop() { return sum ? the_stack[--sum] : -1; }
inline int push(int x) { the_stack[sum++]=x; }
inline int operator[](const int &x) const{
return the_stack[x-1];
}
inline void clear() { sum=0; }
}st;
inline long long read() {
long long x;char ch;bool f;
for(f=0;!isdigit(ch=getchar());f=ch=='-');
for(x=ch-48;isdigit(ch=getchar());x=x*10+ch-48);
return f?-x:x;
}
inline void print(long long x,char las) {
if(!x) {
putchar(48),putchar(las);
return ;
}
if(x<0) putchar('-'),x=-x;
int ls[23],k=0;
while(x) ls[++k]=x%10,x/=10;
while(k) putchar(ls[k--]+48);
putchar(las);
return ;
}
struct vector {
double x,y;
inline void output() {
printf("%.1lf %.1lf\n",x,y);
return ;
}
inline double len() {
return sqrt(x*x+y*y);
}
inline bool operator!=(const vector &ls) const {
return x!=ls.x || y!=ls.y;
}
inline vector operator+(const vector &ls) const {
return {x+ls.x,y+ls.y};
}
inline void operator+=(const vector &ls) {
x+=ls.x;
y+=ls.y;
return ;
}
inline vector operator-(const vector &ls) const {
return {x-ls.x,y-ls.y};
}
inline void operator-=(const vector &ls) {
x-=ls.x;
y-=ls.y;
return ;
}
inline vector operator*(const double &ls) const {
return {x*ls,y*ls};
}
inline void operator*=(const double &ls) {
x*=ls;
y*=ls;
return ;
}
inline vector operator/(const double &ls) const {
return {x/ls,y/ls};
}
inline void operator/=(const double &ls) {
x/=ls;
y/=ls;
return ;
}
inline double operator*(const vector &ls) const {
return x*ls.y-y*ls.x;
}
inline double operator^(const vector &ls) const {
return x*ls.x+y*ls.y;
}
};
struct node {
int name;double dist=1e15;
inline bool operator<(const node&ls) const {
return dist>ls.dist;
}
};
struct edge {
int to;double len;
edge *next=NULL;
};
struct graph {
edge rd[10000],*head[101];
int rs=0;
inline void add(int x,int y,double len) {
rd[rs].to=y;rd[rs].next=head[x];rd[rs].len=len;head[x]=&rd[rs++];
return ;
}
};
int n=read();
std::priority_queue<node>q1;
std::bitset<10001>in;
inline void done() {
int s=read(),t=read(),a=read(),b=read();double ans=1e15;
graph g1;vector city[s*4+1];node nd[s*4+1];
for(int i=1;i<=s;i++) {
double tt;
for(int j=1;j<=3;j++) city[(i-1)*4+j].x=read(),city[(i-1)*4+j].y=read(),nd[(i-1)*4+j].name=(i-1)*4+j;
tt=read();
if(((city[(i-1)*4+1]-city[(i-1)*4+2])^(city[(i-1)*4+1]-city[(i-1)*4+3]))==0.0) {
vector ls=city[(i-1)*4+2]+city[(i-1)*4+3];
ls/=2;
city[i*4]=ls*2-city[i*4-3];
}else if(((city[(i-1)*4+2]-city[(i-1)*4+1])^(city[(i-1)*4+2]-city[(i-1)*4+3]))==0.0) {
vector ls=city[(i-1)*4+1]+city[(i-1)*4+3];
ls/=2;
city[i*4]=ls*2-city[i*4-2];
}else {
vector ls=city[(i-1)*4+2]+city[(i-1)*4+1];
ls/=2;
city[i*4]=ls*2-city[i*4-1];
}
nd[i*4].name=i*4;
for(int j=1;j<=4;j++) {
for(int k=1;k<=i*4-4;k++) {
double dis=(city[i*4-4+j]-city[k]).len()*t;
g1.add(i*4-4+j,k,dis);g1.add(k,i*4-4+j,dis);
}
for(int k=1;k<j;k++) {
double dis=(city[i*4-4+j]-city[i*4-4+k]).len()*tt;
g1.add(i*4-4+j,i*4-4+k,dis);g1.add(i*4-4+k,i*4-4+j,dis);
}
}
}
nd[a*4-3].dist=nd[a*4-2].dist=nd[a*4-1].dist=nd[a*4].dist=0;
q1.push(nd[a*4-3]),q1.push(nd[a*4-2]),q1.push(nd[a*4-1]),q1.push(nd[a*4]);
while(!q1.empty()) {
node now=q1.top();q1.pop();
if(in[now.name]) continue;
in[now.name]=1;
for(edge *i=g1.head[now.name];i;i=i->next) {
int nex=i->to;
if(nd[nex].dist>now.dist+i->len) {
nd[nex].dist=now.dist+i->len;
q1.push(nd[nex]);
}
}
}
for(int i=1;i<=4;i++) ans=std::min(ans,nd[b*4-4+i].dist);
printf("%.1lf\n",ans);
in.reset();
return ;
}
int main() {
while(n--) done();
return 0;
}