Submission #1389929
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
const int INFINT = INT_MAX/2;
#define REP(i,n) for(int i=0;i<(int)n;++i)
struct Edge{
int dst;
int weight;
Edge(int dst, int weight): dst(dst), weight(weight) {}
};
struct TmpDist{
int vertex;
int dist;
TmpDist(int vertex, int dist): vertex(vertex), dist(dist) {}
bool operator< (const TmpDist& right)const{
return dist > right.dist;
}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
vector<int> dijkstra(Graph &G, int r){
int V = G.size();
vector<int> dist(V, INFINT);
priority_queue<TmpDist> pq;
vector<bool> check(V, false);
TmpDist init(r, 0);
pq.push(init);
while(!pq.empty()){
TmpDist td = pq.top();pq.pop();
int now = td.vertex;
if(!check[now]){
check[now] = true;
dist[now] = td.dist;
for (int i=0;i<G[now].size();i++){
if(dist[G[now][i].dst] > td.dist + G[now][i].weight){
TmpDist tdCandidate(G[now][i].dst, td.dist + G[now][i].weight);
pq.push(tdCandidate);
}
}
}
}
return dist;
}
int main(){
int N, M, R, T;
cin >> N >> M >> R >> T;
Graph G(N);
REP(i, M){
int a, b, c;
cin >> a >> b >> c;
a--;b--;
Edge e1(b, c), e2(a, c);
G[a].push_back(e1);
G[b].push_back(e2);
}
ll res = 0;
REP(i, N){
vector<int> dist = dijkstra(G, i);
sort(dist.begin(), dist.end());
vector<int> dist1(N), dist2(N);
REP(j, N){
dist1[j] = T*dist[j];
dist2[j] = R*dist[j];
}
for(int j=1;j<N;j++){
int add = lower_bound(dist2.begin(), dist2.end(), dist1[j]) - dist2.begin()-1;
if(j<=add) add--;
res += add;
}
}
cout << res << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - ウサギとカメ |
User |
theory_and_me |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
2168 Byte |
Status |
AC |
Exec Time |
905 ms |
Memory |
512 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 |
5 ms |
256 KB |
subtask1_06.txt |
AC |
9 ms |
256 KB |
subtask1_07.txt |
AC |
74 ms |
384 KB |
subtask1_08.txt |
AC |
50 ms |
384 KB |
subtask1_09.txt |
AC |
307 ms |
384 KB |
subtask1_10.txt |
AC |
234 ms |
384 KB |
subtask1_11.txt |
AC |
148 ms |
384 KB |
subtask1_12.txt |
AC |
775 ms |
384 KB |
subtask1_13.txt |
AC |
774 ms |
384 KB |
subtask1_14.txt |
AC |
889 ms |
384 KB |
subtask1_15.txt |
AC |
643 ms |
384 KB |
subtask1_16.txt |
AC |
905 ms |
512 KB |