Submission #8063729
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x) \
for(auto &youso_ : (x)) cin >> youso_
#define bitcnt(x) __builtin_popcount(x)
#define lbit(x) __builtin_ffsll(x)
#define rbit(x) __builtin_clzll(x)
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()
template <typename T = long long> inline T IN() {
T x;
cin >> x;
return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
cin >> head;
CIN(move(tail)...);
}
#define CCIN(...) \
char __VA_ARGS__; \
CIN(__VA_ARGS__)
#define DCIN(...) \
double __VA_ARGS__; \
CIN(__VA_ARGS__)
#define LCIN(...) \
ll __VA_ARGS__; \
CIN(__VA_ARGS__)
#define SCIN(...) \
string __VA_ARGS__; \
CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v) \
{ \
FOREACH(x, v) { cout << x << " "; } \
cout << "\n"; \
}
template <typename T = string> inline void eputs(T s) {
cout << s << "\n";
exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;
typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
// const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793238
// size用
struct UnionFind {
vector<ll> par;
vector<ll> sizes;
UnionFind(ll n) : par(n), sizes(n, 1) { REP(i, n) par[i] = i; }
ll find(ll x) {
if(x == par[x]) return x;
return par[x] = find(par[x]);
}
void unite(ll x, ll y) {
x = find(x);
y = find(y);
if(x == y) return;
if(sizes[x] < sizes[y]) swap(x, y);
par[y] = x;
sizes[x] += sizes[y];
sizes[y] = 0;
}
bool same(ll x, ll y) { return find(x) == find(y); }
ll size(ll x) { return sizes[find(x)]; }
};
struct edge {
ll from, to;
double cost, time;
bool operator<(const edge &another) const { return cost < another.cost; };
bool operator>(const edge &another) const { return cost > another.cost; };
};
vector<edge> es;
#define EPS (1e-3)
signed main() {
LCIN(N, M);
REP(i, M) {
LCIN(A, B);
DCIN(C, T);
es.push_back({A, B, C, T});
}
auto check = [&](double x) {
UnionFind uf(N);
auto f = [x](edge e) { return e.time * x - e.cost; };
sort(All(es), [f](edge a, edge b) { return f(a) > f(b); });
double sum = 0;
FOREACH(e, es) {
if(f(e) > 0 || !uf.same(e.from, e.to)) {
uf.unite(e.from, e.to);
sum += f(e);
}
}
return sum >= 0;
};
double lb = 0, ub = 1e12;
while(ub - lb > EPS) {
double mid = (ub + lb) / 2;
if(check(mid))
ub = mid;
else
lb = mid;
}
cout << ub << "\n";
}
Submission Info
Submission Time |
|
Task |
D - 道を直すお仕事 |
User |
arktan763 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
4661 Byte |
Status |
WA |
Exec Time |
61 ms |
Memory |
1148 KB |
Judge Result
Set Name |
Sample |
Subtask1 |
Subtask2 |
Score / Max Score |
0 / 0 |
0 / 20 |
0 / 80 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
Subtask1 |
sample_01.txt, sample_02.txt, sample_03.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, subtask1_17.txt |
Subtask2 |
sample_01.txt, sample_02.txt, sample_03.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, subtask1_17.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
1 ms |
256 KB |
sample_02.txt |
AC |
1 ms |
256 KB |
sample_03.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 |
1 ms |
256 KB |
subtask1_06.txt |
AC |
1 ms |
256 KB |
subtask1_07.txt |
WA |
1 ms |
256 KB |
subtask1_08.txt |
AC |
1 ms |
256 KB |
subtask1_09.txt |
AC |
1 ms |
256 KB |
subtask1_10.txt |
AC |
1 ms |
256 KB |
subtask1_11.txt |
AC |
1 ms |
256 KB |
subtask1_12.txt |
AC |
1 ms |
256 KB |
subtask1_13.txt |
AC |
1 ms |
256 KB |
subtask1_14.txt |
AC |
1 ms |
256 KB |
subtask1_15.txt |
AC |
1 ms |
256 KB |
subtask1_16.txt |
AC |
1 ms |
256 KB |
subtask1_17.txt |
AC |
1 ms |
256 KB |
subtask2_01.txt |
AC |
12 ms |
512 KB |
subtask2_02.txt |
AC |
8 ms |
384 KB |
subtask2_03.txt |
WA |
16 ms |
576 KB |
subtask2_04.txt |
AC |
55 ms |
1148 KB |
subtask2_05.txt |
AC |
60 ms |
1148 KB |
subtask2_06.txt |
AC |
61 ms |
1148 KB |
subtask2_07.txt |
AC |
51 ms |
1148 KB |
subtask2_08.txt |
AC |
57 ms |
1148 KB |
subtask2_09.txt |
AC |
61 ms |
1148 KB |
subtask2_10.txt |
AC |
31 ms |
704 KB |
subtask2_11.txt |
AC |
39 ms |
764 KB |
subtask2_12.txt |
AC |
40 ms |
764 KB |