結果
| 問題 |
No.3013 ハチマキ買い星人
|
| コンテスト | |
| ユーザー |
Tatsu_mr
|
| 提出日時 | 2025-01-25 13:00:22 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 175 ms / 2,000 ms |
| コード長 | 3,960 bytes |
| コンパイル時間 | 3,684 ms |
| コンパイル使用メモリ | 289,704 KB |
| 実行使用メモリ | 31,768 KB |
| 最終ジャッジ日時 | 2025-01-25 22:29:49 |
| 合計ジャッジ時間 | 9,813 ms |
|
ジャッジサーバーID (参考情報) |
judge7 / judge11 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define For(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) For(i, 0, n)
#define rFor(i, a, b) for(int i = (a); i >= (b); i--)
#define ALL(v) (v).begin(), (v).end()
#define rALL(v) (v).rbegin(), (v).rend()
using lint = long long;
using ld = long double;
int INF = 2000000000;
lint LINF = 1000000000000000000;
template <class T>
struct Edge {
int from, to;
T cost;
int idx;
Edge() {}
Edge(int to_) : to(to_) {}
Edge(int to_, T cost_) : to(to_), cost(cost_) {}
Edge(int from_, int to_, int idx_) : from(from_), to(to_), idx(idx_) {}
Edge(int from_, int to_, T cost_, int idx_) : from(from_), to(to_), cost(cost_), idx(idx_) {}
};
template <class T>
struct StaticGraph {
private:
template <class It>
struct Es {
It b, e;
It begin() const { return b; }
It end() const { return e; }
int size() const { return int(e - b); }
auto &&operator[](int i) const { return b[i]; }
};
int n;
vector<pair<int, Edge<T>>> es;
vector<int> start;
vector<Edge<T>> eli;
bool built;
public:
StaticGraph() {}
StaticGraph(int n_) : n(n_), start(n + 1), built(false) {}
void add(int u, int v) {
assert(!built);
assert(0 <= u && u < n);
assert(0 <= v && v < n);
es.emplace_back(u, (Edge<T>){v});
}
void add(int u, int v, T w) {
assert(!built);
assert(0 <= u && u < n);
assert(0 <= v && v < n);
es.emplace_back(u, (Edge<T>){v, w});
}
void add(int u, int u_, int v, int i) {
assert(!built);
assert(0 <= u && u < n);
assert(u == u_);
assert(0 <= v && v < n);
es.emplace_back(u, (Edge<T>){u, v, i});
}
void add(int u, int u_, int v, T w, int i) {
assert(!built);
assert(0 <= u && u < n);
assert(0 <= v && v < n);
assert(u == u_);
es.emplace_back(u, (Edge<T>){u, v, w, i});
}
void build() {
if (built) {
return;
}
eli.resize(es.size());
for (auto [v, e] : es) {
start[v + 1]++;
}
for (int i = 1; i <= n; i++) {
start[i] += start[i - 1];
}
auto counter = start;
for (auto [v, e] : es) {
eli[counter[v]++] = e;
}
built = true;
}
int size() const {
return n;
}
Es<typename vector<Edge<T>>::iterator> operator[](int v) {
assert(built);
assert(0 <= v && v < n);
return {eli.begin() + start[v], eli.begin() + start[v + 1]};
}
};
template <class T>
vector<T> Dijkstra(StaticGraph<T> &g, int s) {
T mx = (is_same<T, int>::value ? 2000000000 : 1000000000000000000);
vector<T> d(g.size(), mx);
priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
d[s] = T(0);
pq.emplace(d[s], s);
while (!pq.empty()) {
auto [c, v] = pq.top();
pq.pop();
if (d[v] < c) {
continue;
}
for (auto &e : g[v]) {
int nv = e.to;
T nc = c + e.cost;
if (d[nv] > nc) {
d[nv] = nc;
pq.emplace(d[nv], nv);
}
}
}
return d;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, p;
lint y;
cin >> n >> m >> p >> y;
StaticGraph<lint> g(n);
rep(i, m) {
int a, b;
lint c;
cin >> a >> b >> c;
a--;
b--;
g.add(a, b, c);
g.add(b, a, c);
}
g.build();
vector<int> d(p);
vector<lint> e(p);
rep(i, p) {
cin >> d[i] >> e[i];
d[i]--;
}
auto dist = Dijkstra(g, 0);
lint ans = 0;
rep(i, p) {
lint now = y - dist[d[i]];
ans = max(ans, now / e[i]);
}
cout << ans << "\n";
}
Tatsu_mr