#include<bits> using namespace std; typedef long long LL; typedef pair<ll> PII; const int N = 400010, INF = 1e18; int h[N], e[N], ne[N], w[N], idx; map<long long=""> mp; LL dist[N]; bool st[N]; int k = 0; void add(LL a, LL b, LL c) { e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++; } LL dijkstra() { for(int i = 1; i < N; i++) dist[i] = INF; //cout << mp[start] << endl; dist[1] = 0; priority_queue<pii>, greater<pii> >hp; hp.push({0, 1}); while(hp.size()) { PII t = hp.top(); hp.pop(); LL distance = t.first; int ver = t.second; if(st[ver]) continue; st[ver] = true; for(int i = h[ver]; ~i; i = ne[i]) { int j = e[i]; if(dist[j] > dist[ver] + w[i]) { dist[j] = dist[ver] + w[i]; hp.push({dist[j], j}); } } } return dist[2]; //cout << dist[2] << endl; } int main() { memset(h, -1, sizeof h); LL m, s, start, endx; cin >> m >> start >> endx >> s; mp[start] = ++k; mp[endx] = ++k; //cout << k << endl; while(m--) { LL a, b; LL c, d; cin >> a >> b >> c >> d; //cout << 1 << endl; if(!mp.count(a)) mp[a] = ++k; if(!mp.count(b)) mp[b] = ++k; //if(mp[a] == mp[b]) continue; //cout << k << endl; int x = mp[a], y = mp[b]; add(x, y, c); if(d == 2) add(y, x, c); } LL t = dijkstra(); //cout << t << endl; if(t == INF) printf("-1\n"); else printf("%lld\n",(t + s - 1) / s); return 0; } 大佬能帮我看下J题哪里错了吗 我真的不知道哪里错了</pii></pii></long></ll></bits>
点赞

相关推荐

12-03 03:32
安徽大学 Java
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务