题意: 求最小环判断 { 最小环权值于c的大小 }
有向图最小环 {
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
typedef pair<long long,int> PII;
const int N = 5e3+10,M = 2e3+10;
int h[N],e[N],ne[N],idx,w[N];
bool st[M];
long long dist[M][M];
int n,m,tot;
void add(int a,int b,int c){
ne[idx] = h[a],e[idx] = b,w[idx] = c,h[a] = idx++;
}
void dji(int x){
for(int i = 1;i<=n;i++)dist[x][i] = 0x3f3f3f3f3f3f3f3f,st[i] = 0;
priority_queue<PII> q;
q.push({0,x});
dist[x][x] = 0;
while(!q.empty()){
int u = q.top().second;
q.pop();
if(st[u])continue;
st[u] = 1;
for(int i = h[u];~i;i=ne[i]){
int y = e[i];
if(dist[x][y] > dist[x][u] + w[i]){
dist[x][y] = dist[x][u] + w[i];
q.push({-dist[x][y],y});
}
}
}
}
int main(){
bool flag = true;
cin >> n >> m >> tot;
memset(h,-1,sizeof h);
for(int i = 1,a,b,c;i<=m;i++){
cin >> a >> b >> c;
if(c <= tot)add(a,b,c),flag = false;
}
if(flag){
cout << 0 << endl;
return 0;
}
for(int i = 1;i<=n;i++)dji(i);
long long ans = 2e9+10;
for(int i = 1;i<=n;i++)
for(int j = 1;j<=n;j++)
if(i!=j) ans = min(ans,dist[i][j] + dist[j][i]);
if(ans <= tot)cout << 2 << endl;
else cout << 1 << endl;
return 0;
}
}