3 条题解
-
4
观察数据范围,可行流为 是比较好做的,直接在原图上跑最短路即可。然后我也不知道为什么有 分,两个样例都过不了。
正解就是在此代码基础上再加反边。
Update:把 SPFA 换成 Dijkstra 有 分。
#include <bits/stdc++.h> using namespace std; using ll = long long; struct no{ int x, y, c; ll v; } b[200005]; struct p{ int x; ll v; }; int n, m, s, t; ll dis[50005]; bool f[50005]; vector<p> vc[50005]; struct pqz{ int id; ll dis; bool operator < (const pqz &a) const{ return a.dis < dis; } }; void Dijkstra(int s, int t){ memset(dis, 0x3f, sizeof(dis)); memset(f, 0, sizeof(f)); priority_queue<pqz> pq; pq.push({s, 0}); dis[s] = 0; while(!pq.empty()){ int x = pq.top().id; pq.pop(); if(f[x]) continue; f[x] = 1; for(auto i : vc[x]){ if(dis[i.x] > dis[x] + i.v){ dis[i.x] = dis[x] + i.v; pq.push({i.x, dis[i.x]}); } } } } int main(){ freopen("flow.in", "r", stdin); freopen("flow.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); while(cin >> n >> m){ if(!n && !m) return 0; cin >> s >> t; for(int i = 1; i <= m; i++){ int a, d, c; ll v; cin >> a >> d >> c >> v; b[i] = {a, d, c, v}; } for(int i = 1; i <= m; i++){ int f; cin >> f; if(b[i].c > f) vc[b[i].x].push_back({b[i].y, b[i].v}); } Dijkstra(s, t); if(dis[t] > 1e18) dis[t] = -1; cout << dis[t] << '\n'; for(int i = 1; i <= n; i++) vc[i].clear(); } return 0; } /* 6 7 1 6 1 2 3 1 1 3 3 2 2 4 1 3 3 4 2 4 3 5 2 5 4 6 2 6 5 6 3 7 0 3 0 2 1 2 1 4 4 1 4 1 2 1 1 2 4 2 1 1 3 2 1 3 4 1 1 1 1 1 1 0 0 */
- 1
信息
- ID
- 62
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 5
- 标签
- 递交数
- 43
- 已通过
- 18
- 上传者


