0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 01:25:25 +00:00

P1807 最长路

R72243775
This commit is contained in:
Baoshuo Ren 2022-03-24 21:51:04 +08:00
parent b3fcbc9abd
commit 5860aae051
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

50
Luogu/P1807/P1807.cpp Normal file
View File

@ -0,0 +1,50 @@
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1505,
INF = 0x3f3f3f3f;
int n, m, dist[N];
std::vector<std::pair<int, int>> g[N];
void spfa() {
memset(dist, 0xff, sizeof(dist));
std::queue<int> q;
q.push(1);
dist[1] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto e : g[u]) {
int v = e.first,
w = e.second;
if (dist[v] < dist[u] + w) {
dist[v] = dist[u] + w;
q.push(v);
}
}
}
}
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
g[u].push_back(std::make_pair(v, w));
}
spfa();
cout << dist[n] << endl;
return 0;
}