結果
問題 | No.3013 ハチマキ買い星人 |
ユーザー |
|
提出日時 | 2025-01-25 13:39:54 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,383 ms / 2,000 ms |
コード長 | 6,166 bytes |
コンパイル時間 | 6,419 ms |
コンパイル使用メモリ | 334,520 KB |
実行使用メモリ | 25,460 KB |
最終ジャッジ日時 | 2025-01-25 22:54:24 |
合計ジャッジ時間 | 18,825 ms |
ジャッジサーバーID (参考情報) |
judge9 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 45 |
ソースコード
#include <iostream>#include <string>#include <stdio.h>#include <algorithm>#include <vector>#include <tuple>#include <map>#include<set>#include<queue>#include<stack>#include <unordered_set>#include<thread>#include<bits/stdc++.h>#include <numbers>#include <atcoder/all>#include <cstdio>// #pragma GCC target("avx")// #pragma GCC optimize("O3")// #pragma GCC optimize("unroll-loops")//if(a < 0 || h <= a || b < 0 || w <= b)return;using namespace std;using namespace atcoder;using ll = long long;using ld = long double;using ull = unsigned long long;using mint = modint998244353;using mint1 = modint1000000007;//using VL = vector<ll>;template<typename T> using pq = priority_queue<T>;//降順?(最大取り出し)template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;//昇順?(最小取り出し)template<typename T> using vector2 = vector<vector<T>>;template<typename T> using vector3 = vector<vector<vector<T>>>;template<typename T> using vector4 = vector<vector<vector<vector<T>>>>;template<typename T> using vector5 = vector<vector<vector<vector<vector<T>>>>>;template<typename T> using vector6 = vector<vector<vector<vector<vector<vector<T>>>>>>;template<typename T> using pairs = pair<T,T>;#define rep(i, n) for (ll i = 0; i < ll(n); i++)#define rep1(i,n) for(int i = 1;i <= int(n);i++)#define repm(i, m, n) for (int i = (m); (i) < int(n);(i)++)#define repmr(i, m, n) for (int i = (m) - 1; (i) >= int(n);(i)--)#define rep0(i,n) for(int i = n - 1;i >= 0;i--)#define rep01(i,n) for(int i = n;i >= 1;i--)// NのK乗根N < 2^64, K <= 64uint64_t kth_root(uint64_t N, uint64_t K) {assert(K >= 1);if (N <= 1 || K == 1) return N;if (K >= 64) return 1;if (N == uint64_t(-1)) --N;auto mul = [&](uint64_t x, uint64_t y) -> uint64_t {if (x < UINT_MAX && y < UINT_MAX) return x * y;if (x == uint64_t(-1) || y == uint64_t(-1)) return uint64_t(-1);return (x <= uint64_t(-1) / y ? x * y : uint64_t(-1));};auto power = [&](uint64_t x, uint64_t k) -> uint64_t {if (k == 0) return 1ULL;uint64_t res = 1ULL;while (k) {if (k & 1) res = mul(res, x);x = mul(x, x);k >>= 1;}return res;};uint64_t res;if (K == 2) res = sqrtl(N) - 1;else if (K == 3) res = cbrt(N) - 1;else res = pow(N, nextafter(1 / double(K), 0));while (power(res + 1, K) <= N) ++res;return res;}// ユークリッドの互除法による最大公約数算出ll GCD(ll a,ll b){if(b == 0)return a;return GCD(b, a % b);}//拡張ユークリッドの互除法による(ax + by = GCD(a,b))を満たすx,yの算出pair<long long, long long> extgcd(long long a, long long b) {if (b == 0) return make_pair(1, 0);long long x, y;tie(y, x) = extgcd(b, a % b);y -= a / b * x;return make_pair(x, y);}struct UnionFind {vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化for(int i = 0; i < N; i++) par[i] = i;}int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}if (par[x] == x) return x;return par[x] = root(par[x]);}void unite(int x, int y) { // xとyの木を併合int rx = root(x); //xの根をrxint ry = root(y); //yの根をryif (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのままpar[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける}bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返すint rx = root(x);int ry = root(y);return rx == ry;}};ll n;//座標圧縮vector<ll> Ccomp(vector<ll> a){vector<ll> b = a;sort(b.begin(),b.end());b.erase(unique(b.begin(),b.end()),b.end());//ダブり消去vector<ll> rtn;rep(j,a.size()){ll pb = lower_bound(b.begin(),b.end(),a[j]) - b.begin();rtn.push_back(pb);}return rtn;}/// ここから////////////////////////////////////////////using F = ll;using S = ll;string s;ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1;} return ret; }void cincout(){ios::sync_with_stdio(false);std::cin.tie(nullptr);cout<< fixed << setprecision(15);}//seg,遅延segの設定-----ここからS op(S a,S b){return min(a,b);}S e(){return ll(1e15);};S mapping (F a,S b){return a + b;}//遅延処理F composition (F a,F b){return a+b;}//遅延中の枝にさらに処理F id(){return 0;}//遅延のモノイド//segここまでstring abc = "abcdefghijklmnopqrstuvwxyz";string Labc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";ll INF = ll(1e18);ll mod = 998244353;ll mod1 = ll(1e9) + 7;int inf = int(1e9+10);vector<ll> movey = {-1,0,1,0},movex = {0,1,0,-1};bool outc(ll nowy,ll nowx,ll h,ll w){if(nowy < 0 || nowy >= h || nowx < 0 || nowx >= w){return 0;}return 1;}ll maxim = 200000;signed main() {cincout();ll m,p,y;cin >> n >> m >> p >> y;vector edge(n,vector<pairs<ll>>(0));rep(j,m){ll a,b,c;cin >> a >> b >> c;a--,b--;edge[a].push_back({b,c});edge[b].push_back({a,c});}ll ans = 0;pqg<pairs<ll>> que;que.push({0,0});vector<ll> shop(n,INF);rep(j,p){ll x,c;cin >> x >> c;x--;shop[x] = c;}vector<ll> dig(n,INF);while(que.size()){ll now,cost;tie(now,cost) = que.top();que.pop();if(dig[now] <= cost)continue;dig[now] = cost;ans = max(ans,(y-cost) / shop[now]);for(auto j : edge[now]){ll to,toc;tie(to,toc) = j;if(dig[to] > toc + cost)que.push({to,toc + cost});}}cout << ans << endl;return 0;}