38 条题解
-
0
http://ybt.ssoier.cn:8088/problem_show.php?pid=1509
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 10; const int INF = 0x3f3f3f3f; int n; int u , v , w , maxx; vector<pair<int,int> > vc[N]; int dis[N]; bool vis[N]; void spfa()//求最长路!!! { memset(dis, -INF, sizeof(dis)); dis[0] = 0; vis[0] = 1;//表示当前点是否在队列中 queue<int> q; q.push(0); while(!q.empty()) { int u = q.front(); q.pop(); vis[u] = 0; for(int i = 0; i < vc[u].size(); i++) { int v = vc[u][i].first , w = vc[u][i].second; if(dis[v] < dis[u] + w) { dis[v] = dis[u] +w; if(!vis[v]) { q.push(v); vis[v] = 1; } } } } } int main() { cin >> n; for(int i = 1; i <= n; i++) { cin >> u >> v >> w; u++ , v++;//整体右移 //sum[v] - sum[u - 1] >= w vc[u - 1].push_back({v , w}); maxx = max(maxx , v); } //隐藏不等式 sum[i] - sum[i - 1] >= 0 sum[i - 1] - sum[i] >= -1 for(int i = 1; i <= maxx; i++) { vc[i - 1].push_back({i , 0}); vc[i].push_back({i - 1, -1}); } spfa(); cout << dis[maxx]; return 0; }
信息
- ID
- 1
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 1
- 标签
- 递交数
- 4986
- 已通过
- 1406
- 上传者