Algo-Trian

This commit is contained in:
e2hang
2025-09-21 12:21:50 +08:00
parent 24522486f1
commit 3bde00039c
25 changed files with 842 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
#include <iostream>
#include <vector>
#include <tuple>
using namespace std;
const int INF = 100001;//<2F><><EFBFBD><EFBFBD>
int main(){
//dp<64>ķֽ׶<D6BD><D7B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD>ӽṹ<D3BD><E1B9B9><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>)
int n, edge_num, start, end;
cin >> n >> edge_num >> start >> end;
//<2F><><EFBFBD>ش洢
//vector<tuple<int, int, int>> edge(edge_num);
vector<vector<int>> dp(n, vector<int>(n, INF));
for(int i = 0; i < edge_num; i++){
int a, b, w;
cin >> a >> b >> w;
//edge[i] = {a, b, w};
dp[a][b] = w;
}
//dp, һ<><D2BB><EFBFBD><EFBFBD><6B><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for(int k = 0; k < n; k++){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}
}
}
for(int k = 0; k < n; k++){
if(dp[k][k] < 0){
cout << "Negative Cycle Detected!" << endl;
return 0;
}
}
cout << dp[start][end] << endl;
return 0;
}