mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-05-10 16:20:27 +08:00
New: total 2 codes
This commit is contained in:
parent
c8863a5850
commit
5233639a89
63
FZOI/【模板】负环.cpp
Normal file
63
FZOI/【模板】负环.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
#define lo long long
|
||||||
|
#define INF 0x3f3f3f3f3f3f3f3fl
|
||||||
|
#define LLM LONG_LONG_MAX
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
const lo N = 1e5 + 10;
|
||||||
|
/*
|
||||||
|
toothless. #17
|
||||||
|
@fredcss_dev
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct Edge {
|
||||||
|
lo u, v, w;
|
||||||
|
};
|
||||||
|
|
||||||
|
lo t, n, m;
|
||||||
|
lo c, p, W;
|
||||||
|
|
||||||
|
vector<Edge> edge;
|
||||||
|
|
||||||
|
lo dis[N], u, v, w;
|
||||||
|
|
||||||
|
bool bellmanford(lo n, lo s)
|
||||||
|
{
|
||||||
|
memset(dis, 0x3f, (n + 1) * sizeof(lo));
|
||||||
|
dis[s] = 0;
|
||||||
|
bool flag = false;
|
||||||
|
for (lo i = 1; i <= n; i++) {
|
||||||
|
flag = false;
|
||||||
|
for (lo j = 0; j < edge.size(); j++) {
|
||||||
|
u = edge[j].u, v = edge[j].v, w = edge[j].w;
|
||||||
|
if (dis[u] == INF) continue;
|
||||||
|
if (dis[v] > dis[u] + w) {
|
||||||
|
dis[v] = dis[u] + w;
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!flag) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
signed main()
|
||||||
|
{
|
||||||
|
cin >> t;
|
||||||
|
while (t--) {
|
||||||
|
edge.clear();
|
||||||
|
cin >> n >> m;
|
||||||
|
for (lo i = 1; i <= m; i++) {
|
||||||
|
cin >> c >> p >> W;
|
||||||
|
edge.push_back({c, p, W});
|
||||||
|
if (W >= 0) edge.push_back({p, c, W});
|
||||||
|
}
|
||||||
|
if (bellmanford(n, 1)) {
|
||||||
|
cout << "YES" << endl;
|
||||||
|
} else {
|
||||||
|
cout << "NO" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
FZOI/最短路径问题.cpp
Normal file
55
FZOI/最短路径问题.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
#define lo long long
|
||||||
|
#define INF INT_MAX
|
||||||
|
#define LLM LONG_LONG_MAX
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
const int N = 1e7 + 10;
|
||||||
|
/*
|
||||||
|
toothless. #17
|
||||||
|
@fredcss_dev
|
||||||
|
*/
|
||||||
|
|
||||||
|
int n, m, s, t;
|
||||||
|
double ma[101][101], dp[101][101];
|
||||||
|
|
||||||
|
struct Node {
|
||||||
|
int x, y;
|
||||||
|
} a[101];
|
||||||
|
|
||||||
|
signed main()
|
||||||
|
{
|
||||||
|
ios::sync_with_stdio(0);
|
||||||
|
cin.tie(0);
|
||||||
|
cout.tie(0);
|
||||||
|
cin >> n;
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
cin >> a[i].x >> a[i].y;
|
||||||
|
}
|
||||||
|
cin >> m;
|
||||||
|
for (int i = 1; i <= m; i++) {
|
||||||
|
int c, d;
|
||||||
|
cin >> c >> d;
|
||||||
|
double k = sqrt(double(pow((a[c].x - a[d].x), 2)) + double(pow((a[c].y - a[d].y), 2)));
|
||||||
|
ma[c][d] = k;
|
||||||
|
ma[d][c] = k;
|
||||||
|
}
|
||||||
|
cin >> s >> t;
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
for (int j = 1; j <= n; j++) {
|
||||||
|
if (ma[i][j]) {
|
||||||
|
dp[i][j] = ma[i][j];
|
||||||
|
} else {
|
||||||
|
dp[i][j] = INT_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int k = 1; k <= n; k++) {
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
for (int j = 1; j <= n; j++) {
|
||||||
|
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("%.2lf", dp[s][t]);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user