結果
| 問題 |
No.3013 ハチマキ買い星人
|
| コンテスト | |
| ユーザー |
Cafe1942
|
| 提出日時 | 2025-01-25 14:55:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 297 ms / 2,000 ms |
| コード長 | 1,793 bytes |
| コンパイル時間 | 1,014 ms |
| コンパイル使用メモリ | 105,528 KB |
| 実行使用メモリ | 23,344 KB |
| 最終ジャッジ日時 | 2025-01-25 23:32:32 |
| 合計ジャッジ時間 | 8,978 ms |
|
ジャッジサーバーID (参考情報) |
judge10 / judge11 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 45 |
ソースコード
#include <iostream>
#include <iomanip>//小数点出力用
//cout << fixed << setprecision(10) << ans;
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using ll = long long;
using namespace std;
#define modP 998244353
bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); }
int clk4(int num) { return (num - 2) * (num % 2); }
void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;cin >> N >> M;
int P;cin >> P;
ll Y;cin >> Y;
vector<pair<int, int>>nxt[200002];
for (int i = 0;i < M;i++) {
int A, B, C;cin >> A >> B >> C;
nxt[A].push_back({ B,C });
nxt[B].push_back({ A,C });
}
ll cost[200002];
for (int i = 2;i <= N;i++)cost[i] = 2e18;
bool ok[200002] = { 0 };
priority_queue<pair<ll, int>>Q;
Q.push({ 0,1 });
while (!Q.empty()) {
int now = Q.top().second;
if (ok[now]) {
Q.pop();
continue;
}
ok[now] = 1;
cost[now] = Q.top().first * (-1);
Q.pop();
for (int j = 0;j < nxt[now].size();j++) {
if (ok[nxt[now][j].first])continue;
if (cost[nxt[now][j].first] > cost[now] + nxt[now][j].second) {
cost[nxt[now][j].first] = cost[now] + nxt[now][j].second;
Q.push({ -1 * cost[nxt[now][j].first] ,nxt[now][j].first });
}
}
}
map<int, ll>MP;
for(int i=0;i<P;i++){
int D, E;cin >> D >> E;
MP[D] = E;
}
ll ans = 0;
for (int i = 1;i <= N;i++) {
if (MP.find(i) == MP.end())continue;
ans = max(ans, (Y - cost[i]) / MP[i]);
}
cout << ans;
return 0;
}
Cafe1942