Submission #1609772
Source Code Expand
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1e15
struct edge{
int to,cost;
edge(){}
edge(int x, int y){
to = x;
cost = y;
}
};
VL dijkstra(vector<vector<edge> > &graph, int st = 0){
int n = graph.size();
VL d(n, INF);
d[st] = 0;
priority_queue<P, vector<P>, greater<P> > q;
q.push(make_pair(0, st));
while (!q.empty()){
P a = q.top();
q.pop();
int now = a.second;
if(d[now] < a.first) continue;
REP(i,graph[now].size()){
edge e = graph[now][i];
int next = e.to;
if (d[next] > d[now] + e.cost){
d[next] = d[now] + e.cost;
q.push(make_pair(d[next], next));
}
}
}
return d;
}
int main(){
int n, m, r, t;
cin >> n >> m >> r >> t;
vector<vector<edge> > e(n);
REP(i,m){
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
a--;
b--;
e[a].push_back(edge(b,c));
e[b].push_back(edge(a,c));
}
ll ans = 0;
REP(s,n){
VL d = dijkstra(e, s);
sort(ALL(d));
d.erase(d.begin());
reverse(ALL(d));
// cout << s << endl;
// for (ll p : d) cout << p << " ";
// cout << endl;
int j = 0;
REP(i,n-1){
while (j < n-1 && r * d[i] < t * d[j]) j++;
if (j <= i) ans += j;
else ans += j - 1;
}
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - ウサギとカメ |
User |
TangentDay |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
2138 Byte |
Status |
AC |
Exec Time |
1001 ms |
Memory |
384 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:70:38: 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 |
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 |
256 KB |
subtask1_07.txt |
AC |
28 ms |
384 KB |
subtask1_08.txt |
AC |
35 ms |
256 KB |
subtask1_09.txt |
AC |
301 ms |
384 KB |
subtask1_10.txt |
AC |
281 ms |
384 KB |
subtask1_11.txt |
AC |
126 ms |
384 KB |
subtask1_12.txt |
AC |
899 ms |
384 KB |
subtask1_13.txt |
AC |
898 ms |
384 KB |
subtask1_14.txt |
AC |
997 ms |
384 KB |
subtask1_15.txt |
AC |
681 ms |
384 KB |
subtask1_16.txt |
AC |
1001 ms |
384 KB |