比赛 |
4043级2023省选模拟赛9 |
评测结果 |
AAAAAAAAAA |
题目名称 |
最小圈 |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
0.029 s |
代码语言 |
C++ |
内存使用 |
3.04 MiB |
提交时间 |
2023-03-30 10:22:52 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=3000+5;
const int M=10000+5;
const double eps=1e-10;
struct sdf{
int to,next;double w;
}eg[2*M];
int head[N],ne=0;
void add(int x,int y,double w){
eg[++ne]={y,head[x],w};
head[x]=ne;return ;
}
int n,m;
bool ins[N];
double dis[N];
bool spfa(int pt,double mid){
ins[pt]=1;
for (int i=head[pt];i!=0;i=eg[i].next){
int v=eg[i].to;double w=eg[i].w-mid;
if (dis[v]>dis[pt]+w){
dis[v]=dis[pt]+w;
if (ins[v]||spfa(v,mid)) return 1;
}
}
ins[pt]=0;return 0;
}
bool chck(double mid){
for (int i=1;i<=n;i++)ins[i]=dis[i]=0;
for (int i=1;i<=n;i++)if (spfa(i,mid))return 1;
return 0;
}
int main(){
freopen ("minicycle.in","r",stdin);
freopen ("minicycle.out","w",stdout);
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++){
int x,y;double w;
scanf("%d%d%lf",&x,&y,&w);
add(x,y,w);
}
double l=-1e7,r=1e7;
while(fabs(l-r)>eps){
double mid=(l+r)/2;
if (chck(mid))r=mid;
else l=mid;
}
printf("%.8lf\n",l);
}