Submission #1511416
Source Code Expand
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;
class Edge{
public:
int to, cost;
Edge(int to, int cost) : to(to) ,cost(cost) {}
};
class Node{
public:
double dis;
bool isUsed;
Node(){
this->dis = INF;
this->isUsed = 0;
}
bool operator < ( const Node &right ) const {
return dis < right.dis;
}
};
typedef vector<vector<Edge>> AdjList;
int dijkstra(AdjList g, int start, int n, double r, double t){
vector<Node> node(n);
priority_queue<double, vector<pair<double, int>>, greater<pair<double, int>>> q;
q.push(make_pair(0, start));
node[start].dis = 0;
pair<int, int> u;
while(not q.empty()){
u = q.top(); q.pop();
int current = u.second;
node[current].isUsed = 1;
rep(i,g[current].size()){
int next = g[current][i].to;
if(node[next].isUsed == 0){
if(node[next].dis > node[current].dis + g[current][i].cost){
node[next].dis = node[current].dis + g[current][i].cost;
q.push(make_pair(node[next].dis, next));
}
}
}
}
sort(all(node));
rep(i,n) node[i].dis /= r;
int ans = 0;
range(i,1,n){
Node tmp;
tmp.dis = node[i].dis / t * r + 1e-8;
ans += node.end() - upper_bound(all(node), tmp);
}
return ans;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
double r, t;
cin >> n >> m >> r >> t;
AdjList g(n);
rep(i,m){
int a, b, c;
cin >> a >> b >> c;
a--; b--;
g[a].emplace_back(Edge{b,c});
g[b].emplace_back(Edge{a,c});
}
int ans = 0;
rep(i,n){
ans += dijkstra(g,i,n,r,t);
}
cout << ans << endl;
}
Submission Info
Submission Time |
|
Task |
C - ウサギとカメ |
User |
noy72 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2135 Byte |
Status |
WA |
Exec Time |
1604 ms |
Memory |
640 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 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 |
9 ms |
256 KB |
subtask1_06.txt |
WA |
12 ms |
256 KB |
subtask1_07.txt |
AC |
49 ms |
384 KB |
subtask1_08.txt |
WA |
56 ms |
384 KB |
subtask1_09.txt |
AC |
491 ms |
512 KB |
subtask1_10.txt |
AC |
457 ms |
512 KB |
subtask1_11.txt |
AC |
204 ms |
384 KB |
subtask1_12.txt |
WA |
1474 ms |
640 KB |
subtask1_13.txt |
WA |
1460 ms |
640 KB |
subtask1_14.txt |
WA |
1604 ms |
640 KB |
subtask1_15.txt |
AC |
1102 ms |
640 KB |
subtask1_16.txt |
WA |
1603 ms |
640 KB |