Submission #1107022
Source Code Expand
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;
#define INF 1e9
int n;
int m, r, t;
struct Edge {
int cost;
int to;
Edge(){}
Edge(int c, int t) : cost(c), to(t) {}
};
vv<Edge> g; // 隣接リスト
vector<int> d;
//typedef pair<int, int> pii; // cost, node
void dijkstra(int s) {
d.assign(n, INF);
priority_queue<pii, vector<pii>, greater<pii> > q;
d[s] = 0;
q.push(make_pair(0, s));
while (!q.empty()) {
auto p = q.top();
q.pop();
int v = p.second;
if (d[v] < p.first) {
continue;
}
for (auto e : g[v]) {
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
q.push(make_pair(d[e.to], e.to));
}
}
}
}
int main() {
scanf("%d %d %d %d", &n, &m, &r, &t);
g.resize(n);
int a, b, c;
rep (i, m) {
scanf("%d %d %d", &a, &b, &c);
a -= 1; b -= 1;
Edge e(c, a);
g[b].push_back(e);
e.to = b;
g[a].push_back(e);
}
ll ans = 0;
rep (i, n) {
dijkstra(i);
assert(*(begin(d) + i) == 0);
d.erase(begin(d) + i);
sort(all(d));
vector<int> tortoise(n-1), rabbit(n-1);
rep (j, n-1) {
rabbit[j] = (double)d[j] * t;
tortoise[j] = (double)d[j] * r;
}
rep (j, n-1) { // 若干改善できる
int lb = lower_bound(all(tortoise), rabbit[j]) - begin(tortoise);
ans += lb;
if (lb >= j + 1) {
ans -= 1;
}
}
}
printf("%lld\n", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
C - ウサギとカメ |
User |
tspcx |
Language |
C++11 (GCC 4.8.1) |
Score |
100 |
Code Size |
2347 Byte |
Status |
AC |
Exec Time |
1059 ms |
Memory |
1172 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:74:39: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", &n, &m, &r, &t);
^
./Main.cpp:78:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &a, &b, &c);
^
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 |
18 ms |
1028 KB |
subtask0_sample-02.txt |
AC |
19 ms |
916 KB |
subtask1_01.txt |
AC |
19 ms |
916 KB |
subtask1_02.txt |
AC |
19 ms |
920 KB |
subtask1_03.txt |
AC |
19 ms |
1044 KB |
subtask1_04.txt |
AC |
19 ms |
920 KB |
subtask1_05.txt |
AC |
25 ms |
1048 KB |
subtask1_06.txt |
AC |
26 ms |
1044 KB |
subtask1_07.txt |
AC |
43 ms |
1044 KB |
subtask1_08.txt |
AC |
54 ms |
1044 KB |
subtask1_09.txt |
AC |
314 ms |
1064 KB |
subtask1_10.txt |
AC |
306 ms |
1048 KB |
subtask1_11.txt |
AC |
141 ms |
1044 KB |
subtask1_12.txt |
AC |
985 ms |
1048 KB |
subtask1_13.txt |
AC |
984 ms |
1172 KB |
subtask1_14.txt |
AC |
1044 ms |
1044 KB |
subtask1_15.txt |
AC |
693 ms |
1172 KB |
subtask1_16.txt |
AC |
1059 ms |
1172 KB |