結果
| 問題 |
No.3013 ハチマキ買い星人
|
| ユーザー |
|
| 提出日時 | 2025-01-25 14:02:26 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,945 bytes |
| コンパイル時間 | 1,125 ms |
| コンパイル使用メモリ | 110,628 KB |
| 実行使用メモリ | 47,852 KB |
| 最終ジャッジ日時 | 2025-01-25 23:05:53 |
| 合計ジャッジ時間 | 19,162 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge7 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 38 WA * 7 |
ソースコード
/*
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int p = sc.nextInt();
long y = sc.nextLong();
Dijkstra djk = new Dijkstra(n);
long[] t = new long[n + 1];
for(int i = 1;i <= n;i++) {
t[i] = Long.MAX_VALUE;
}
for(int i = 0;i < m;i++) {
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
djk.addLine(a, b, c);
djk.addLine(b, a, c);
}for(int i = 0;i < p;i++) {
int d = sc.nextInt();
t[d] = sc.nextLong();
}
djk.solve(1,0);
long ans = 0;
for(int i = 1;i <= n;i++) {
long comp = Math.max(0, y - djk.min[i])/t[i];
ans = Math.max(ans, comp);
}System.out.print(ans);
}public static class Dijkstra {
public PriorityQueue<Pair> q = new PriorityQueue<>();
public long[] min;
public boolean[] vis;
public HashMap<Integer,HashSet<Pair>> nextNode = new HashMap<>();
public int n;
public Dijkstra(int n) {
this.n = n;
min = new long[n + 1];
vis = new boolean[n + 1];
for(int i = 1;i <= n;i++) {
min[i] = Long.MAX_VALUE/2;
nextNode.put(i, new HashSet<>());
}
}public void addLine(int from,int to,long cost) {
nextNode.get(from).add(new Pair(cost,to));
}
public void solve(int ind,long val) {
min[ind] = val;
q.add(new Pair(val,ind));
while(!q.isEmpty()) {
Pair p = q.poll();
if(vis[p.x])continue;
vis[p.x] = true;
for(Pair s:nextNode.get(p.x)) {
if(min[s.x] > min[p.x] + s.v) {
min[s.x] = min[p.x] + s.v;
q.add(new Pair(min[s.x],s.x));
}
}
}
}public long getMin(int a) {
return min[a];
}
public static class Pair implements Comparable<Pair> {
long v;
int x;
public Pair(long a,int b) {
v = a;
x = b;
}public int compareTo(Pair p) {
if(this.v < p.v) {
return -1;
}if(this.v > p.v) {
return 1;
}return 0;
}public boolean equals(Object o) {
Pair p = (Pair)o;
return p.x == this.x && p.v == this.v;
}
}
}
}
*/
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <climits>
using namespace std;
class Dijkstra {
public:
struct Pair {
long long v;
int x;
Pair(long long a, int b) : v(a), x(b) {}
bool operator<(const Pair &p) const {
return v > p.v; // Reverse for min-heap
}
};
vector<long long> min;
vector<bool> vis;
map<int, set<Pair>> nextNode;
int n;
Dijkstra(int n) : n(n), min(n + 1, LLONG_MAX / 2), vis(n + 1, false) {}
void addLine(int from, int to, long long cost) {
nextNode[from].insert(Pair(cost, to));
}
void solve(int ind, long long val) {
priority_queue<Pair> q;
min[ind] = val;
q.push(Pair(val, ind));
while (!q.empty()) {
Pair p = q.top(); q.pop();
if (vis[p.x]) continue;
vis[p.x] = true;
for (const Pair &s : nextNode[p.x]) {
if (min[s.x] > min[p.x] + s.v) {
min[s.x] = min[p.x] + s.v;
q.push(Pair(min[s.x], s.x));
}
}
}
}
};
int main() {
int n, m, p;
long long y;
cin >> n >> m >> p >> y;
Dijkstra djk(n);
vector<long long> t(n + 1, LLONG_MAX);
for (int i = 0; i < m; i++) {
int a, b;
long long c;
cin >> a >> b >> c;
djk.addLine(a, b, c);
djk.addLine(b, a, c);
}
for (int i = 0; i < p; i++) {
int d;
cin >> d;
cin >> t[d];
}
djk.solve(1, 0);
long long ans = 0;
for (int i = 1; i <= n; i++) {
if (t[i] != LLONG_MAX) {
long long comp = max(0LL, (y - djk.min[i]) / t[i]);
ans = max(ans, comp);
}
}
cout << ans << endl;
return 0;
}