Submission #1511410
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:
int 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, int r, int t){
vector<Node> node(n);
priority_queue<int, vector<pair<int, int>>, greater<pair<int, 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 *= t;
int ans = 0;
range(i,1,n){
Node tmp;
tmp.dis = node[i].dis / t * r;
ans += node.end() - upper_bound(all(node), tmp);
}
return ans;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n, m, 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 |
2098 Byte |
Status |
WA |
Exec Time |
1500 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 |
8 ms |
256 KB |
subtask1_06.txt |
WA |
11 ms |
256 KB |
subtask1_07.txt |
AC |
45 ms |
384 KB |
subtask1_08.txt |
WA |
52 ms |
384 KB |
subtask1_09.txt |
AC |
463 ms |
512 KB |
subtask1_10.txt |
AC |
426 ms |
512 KB |
subtask1_11.txt |
AC |
191 ms |
384 KB |
subtask1_12.txt |
WA |
1359 ms |
640 KB |
subtask1_13.txt |
WA |
1372 ms |
640 KB |
subtask1_14.txt |
WA |
1496 ms |
640 KB |
subtask1_15.txt |
AC |
1037 ms |
512 KB |
subtask1_16.txt |
WA |
1500 ms |
640 KB |