Submission #2935203


Source Code Expand

#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>
#include<array>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define ll long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const ll MOD = 1000000007;// 10^9+7
const ll INF = (1ll << 60);

using ld = long double;
struct Edge { ll to, cost; };
enum Kind { RABBIT, TURTLE};
struct Score {
	ld time;
	Kind kind;
	ll place;
	bool operator < (const Score& oth)const {
		if (time != oth.time)return time < oth.time;
		else if (kind != oth.kind)return kind < oth.kind;
		else return place < oth.place;
	}
	bool operator == (const Score& oth)const {
		return (time == oth.time)
			&& (kind == oth.kind)
			&& (place == oth.place);
	}
	bool operator > (const Score& oth)const {
		if (*this == oth)return false;
		if (*this < oth)return false;
		return true;
	}
};

constexpr ll MAX_N = 100000;


//変数
ll N, M, R, T;
array<vector<Edge>, MAX_N> edges;
vector<ll> d;

void dijkstra(ll s)
{
	using P = pair<ll, ll>;
	priority_queue<P, vector<P>, greater<P>> que;
	for (auto& num : d)num = INF;
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first)continue;
		for (auto e : edges[v])
		{
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}





//サブ関数
//入力
void input()
{
	cin >> N >> M >> R >> T;
	d.resize(N);
	REP(i, M)
	{
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		edges[a].push_back({ b,c });
		edges[b].push_back({ a,c });
	}
}

priority_queue<Score, vector<Score>, greater<Score>> make_scores(ll goal)
{
	dijkstra(goal);
	priority_queue<Score, vector<Score>, greater<Score>> pq;

	REP(i, N)if (i != goal)
	{
		pq.push({ (ld)d[i] / R, RABBIT , i });
		pq.push({ (ld)d[i] / T, TURTLE , i });
	}
	return pq;
}

ll count_BC_combination(ll goal)
{
	ll res = 0;
	set<ll> turtleStart;
	auto pq = make_scores(goal);

	while (!pq.empty())
	{
		auto score = pq.top(); pq.pop();
		if (score.kind == TURTLE)
		{
			turtleStart.insert(score.place);
		}
		else {
			ll turtleWay = turtleStart.size();
			if (turtleStart.find(score.place) != turtleStart.end())turtleWay--;
			res += turtleWay;
		}
	}
	return res;
}

//計算
void calc()
{
	ll ans = 0;
	REP(i, N)ans += count_BC_combination(i);
	cout << ans << endl;
}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	debug();
	
	return 0;
}

Submission Info

Submission Time
Task C - ウサギとカメ
User toma25
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2929 Byte
Status AC
Exec Time 4334 ms
Memory 3236 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 18
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 3 ms 2688 KB
subtask0_sample-02.txt AC 2 ms 2560 KB
subtask1_01.txt AC 2 ms 2560 KB
subtask1_02.txt AC 3 ms 2560 KB
subtask1_03.txt AC 3 ms 2560 KB
subtask1_04.txt AC 2 ms 2560 KB
subtask1_05.txt AC 20 ms 2688 KB
subtask1_06.txt AC 24 ms 2688 KB
subtask1_07.txt AC 66 ms 2816 KB
subtask1_08.txt AC 104 ms 2688 KB
subtask1_09.txt AC 1037 ms 2992 KB
subtask1_10.txt AC 1144 ms 2944 KB
subtask1_11.txt AC 389 ms 2816 KB
subtask1_12.txt AC 4250 ms 3200 KB
subtask1_13.txt AC 4227 ms 3208 KB
subtask1_14.txt AC 4300 ms 3232 KB
subtask1_15.txt AC 2489 ms 3076 KB
subtask1_16.txt AC 4334 ms 3236 KB