Submission #2918489
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(int i = (l) ; i < (r); i++)
#define incII(i, l, r) for(int i = (l) ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r) ; i >= (l); i--)
#define inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) < (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define FOR(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)
template<typename T> bool setmin(T & a, T b) { if(b < a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax(T & a, T b) { if(b > a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
// ---- ----
template<typename T> class RPQ : public PQ<T, vector<T>, greater<T>> { };
template<typename Cost> void dijkstra(int start, vector<pair<int, Cost>> g[], Cost dist[]) {
RPQ<pair<Cost, int>> q;
dist[start] = 0;
q.emplace(dist[start], start);
while(! q.empty()) {
auto cp = q.top(); q.pop();
int p = cp.SE;
Cost c = cp.FI;
if(dist[p] != c) { continue; }
for(auto && e : g[p]) {
int ep = e.FI;
Cost ec = e.SE;
if(setmin(dist[ep], dist[p] + ec)) { q.emplace(dist[ep], ep); }
}
}
return;
}
int n, m, r, t, d[2500], INF = 1e6;
vector<pair<int, int>> g[2500];
int main() {
cin >> n >> m >> r >> t;
inc(i, m) {
int a, b, c;
cin >> a >> b >> c;
a--; b--;
g[a].EB(b, c);
g[b].EB(a, c);
}
LL ans = 0;
inc(p, n) {
inc(i, n) { d[i] = INF; }
dijkstra(p, g, d);
sort(d, d + n);
int j = 0;
incID(i, 1, n) {
while(j + 1 < n && t * d[i] > r * d[j + 1]) { j++; }
ans += j - (t <= r ? 0 : 1);
}
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - ウサギとカメ |
User |
FF256grhy |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
2597 Byte |
Status |
AC |
Exec Time |
958 ms |
Memory |
384 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
subtask0_sample-01.txt, subtask0_sample-02.txt |
All |
subtask0_sample-01.txt, subtask0_sample-02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask0_sample-01.txt |
AC |
1 ms |
256 KB |
subtask0_sample-02.txt |
AC |
1 ms |
256 KB |
subtask1_01.txt |
AC |
1 ms |
256 KB |
subtask1_02.txt |
AC |
1 ms |
256 KB |
subtask1_03.txt |
AC |
1 ms |
256 KB |
subtask1_04.txt |
AC |
1 ms |
256 KB |
subtask1_05.txt |
AC |
6 ms |
256 KB |
subtask1_06.txt |
AC |
8 ms |
384 KB |
subtask1_07.txt |
AC |
28 ms |
384 KB |
subtask1_08.txt |
AC |
34 ms |
384 KB |
subtask1_09.txt |
AC |
283 ms |
384 KB |
subtask1_10.txt |
AC |
265 ms |
384 KB |
subtask1_11.txt |
AC |
119 ms |
384 KB |
subtask1_12.txt |
AC |
855 ms |
384 KB |
subtask1_13.txt |
AC |
849 ms |
384 KB |
subtask1_14.txt |
AC |
942 ms |
384 KB |
subtask1_15.txt |
AC |
639 ms |
384 KB |
subtask1_16.txt |
AC |
958 ms |
384 KB |