Submission #1938483
Source Code Expand
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=2550;
//ここまでテンプレ
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef int Weight;
struct Edge {
int src, dst;
Weight weight;
Edge(int src, int dst, Weight weight) :
src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void shortestPath(const Graph &g, int s,
vector<Weight> &dist, vector<int> &prev) {
int n = g.size();
dist.assign(n, INF); dist[s] = 0;
prev.assign(n, -1);
priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
Edge e = Q.top(); Q.pop();
if (prev[e.dst] != -1) continue;
prev[e.dst] = e.src;
FOR(f,g[e.dst]) {
if (dist[f->dst] > e.weight+f->weight) {
dist[f->dst] = e.weight+f->weight;
Q.push(Edge(f->src, f->dst, e.weight+f->weight));
}
}
}
}
vector<int> buildPath(const vector<int> &prev, int t) {
vector<int> path;
for (int u = t; u >= 0; u = prev[u])
path.push_back(u);
reverse(path.begin(), path.end());
return path;
}
int main(){
int N,M,R,T;
cin>>N>>M>>R>>T;
Graph G;
for(int i=0;i<N;i++){
Edges E;
G.pb(E);
}
for(int i=0;i<M;i++){
int a,b,c;
cin>>a>>b>>c;
a--,b--;
G[a].pb(Edge(a,b,c));
G[b].pb(Edge(b,a,c));
}
vint D[SIZE],P[SIZE];
//全点対間について最短距離を求めてソートする
for(int i=0;i<N;i++){
shortestPath(G,i,D[i],P[i]);
sort(D[i].begin(),D[i].end());
}
ll ans=0;
//各点を目的地にして回す
for(int DES=0;DES<N;DES++){
//各店を亀の始点にして回す
for(int TUR=0;TUR<N;TUR++){
//目的地と亀の始点が同じときはスキップ
if(TUR==0)
continue;
//ウサギより亀が速くゴールするようなウサギの始点を二分探索
int ng=0,ok=N;
while(ok-ng>1){
int RAB=(ok+ng)/2;
if(D[DES][RAB]*T>D[DES][TUR]*R)
ok=RAB;
else
ng=RAB;
}
//ウサギの始点集合の数
ll temp=N-ok;
//亀の始点がウサギの始点集合の中にあるなら1引いておく
if(ok<=TUR)
temp--;
ans+=temp;
}
}
cout<<ans<<endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - ウサギとカメ |
User |
takeo1116 |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
3363 Byte |
Status |
AC |
Exec Time |
1333 ms |
Memory |
49536 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 |
384 KB |
subtask0_sample-02.txt |
AC |
1 ms |
384 KB |
subtask1_01.txt |
AC |
1 ms |
384 KB |
subtask1_02.txt |
AC |
1 ms |
384 KB |
subtask1_03.txt |
AC |
1 ms |
384 KB |
subtask1_04.txt |
AC |
1 ms |
384 KB |
subtask1_05.txt |
AC |
7 ms |
640 KB |
subtask1_06.txt |
AC |
9 ms |
768 KB |
subtask1_07.txt |
AC |
31 ms |
1280 KB |
subtask1_08.txt |
AC |
41 ms |
1664 KB |
subtask1_09.txt |
AC |
380 ms |
13696 KB |
subtask1_10.txt |
AC |
376 ms |
15872 KB |
subtask1_11.txt |
AC |
152 ms |
5504 KB |
subtask1_12.txt |
AC |
1230 ms |
49408 KB |
subtask1_13.txt |
AC |
1226 ms |
49408 KB |
subtask1_14.txt |
AC |
1333 ms |
49536 KB |
subtask1_15.txt |
AC |
880 ms |
31872 KB |
subtask1_16.txt |
AC |
1332 ms |
49536 KB |