无向图找最小环。
#include#define inf 0x3f3f3f3f#define met(a,b) memset(a,b,sizeof a)#define pb push_back#define mp make_pair#define rep(i,l,r) for(int i=(l);i<=(r);++i)#define inf 0x3f3f3f3fusing namespace std;typedef long long ll;typedef unsigned long long ull;const int N = 4e3+50;;const int M = 255;const int mod = 998244353;const int mo=123;const double pi= acos(-1.0);typedef pair pii;typedef pair P;int n,m,tot;ll ans;vector edg[N];map p;ll dis[N];int vis[N],mark[N][N];int u[N],v[N],cost[N];ll dij(int s,int t,int add){ priority_queue ,greater
>q; for(int i=1;i<=tot;i++)vis[i]=0,dis[i]=10000000000; q.push(P(0LL,s)); dis[s]=0; while(!q.empty()){ int u=q.top().second; ll d=q.top().first; q.pop(); vis[u]=1; if(d+add>=ans)break; for(auto e : edg[u]){ int v=e.first; int w=e.second; if(mark[u][v])continue; if(dis[v]>dis[u]+w){ dis[v]=dis[u]+w; if(!vis[v]){ q.push(P(dis[v],v)); } } } } return dis[t];}int main(){ int T,cas=0; scanf("%d",&T); while(T--){ scanf("%d",&m); tot=0; ans=10000000000; p.clear();met(mark,0); for(int i=1;i