結果
| 問題 | No.3669 误差绝不允许 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-04 23:02:47 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,055 bytes |
| 記録 | |
| コンパイル時間 | 6,489 ms |
| コンパイル使用メモリ | 607,332 KB |
| 実行使用メモリ | 9,796 KB |
| 最終ジャッジ日時 | 2026-09-04 23:07:26 |
| 合計ジャッジ時間 | 10,640 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 RE * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
//約分を毎回しない
template<class T> struct yuri {
T num, den;
yuri() : num(0), den(1) {}
yuri(T a) : num(a), den(1) {}
yuri(int a) : num(a), den(1) {}
yuri(long long a) : num(a), den(1) {}
yuri(T a, T b) : num(a), den(b) {}
void safe(){
if(num < 0) den *= -1, num *= -1;
T v = gcd(num, den);
num /= v, den /= v;
}
yuri& operator++() { num += den; return *this; }
yuri& operator--() { num -= den; return *this; }
yuri& operator+=(const yuri& rhs) {
num *= rhs.den;
num += rhs.num * den;
den *= rhs.den;
return *this;
}
yuri& operator-=(const yuri& rhs) {
num *= rhs.den;
num -= rhs.num * den;
den *= rhs.den;
return *this;
}
yuri& operator*=(const yuri& rhs) {
num *= rhs.num;
den *= rhs.den;
return *this;
}
yuri& operator/=(const yuri& rhs) {
num *= rhs.den;
den *= rhs.num;
return *this ;
}
yuri operator+() const { return *this; }
yuri operator-() const { return yuri() - *this; }
friend yuri operator+(const yuri lhs, const yuri rhs) {
return yuri(lhs) += rhs;
}
friend yuri operator-(const yuri& lhs, const yuri& rhs) {
return yuri(lhs) -= rhs;
}
friend yuri operator*(const yuri& lhs, const yuri& rhs) {
return yuri(lhs) *= rhs;
}
friend yuri operator/(const yuri& lhs, const yuri& rhs) {
return yuri(lhs) /= rhs;
}
friend bool operator==(const yuri& lhs, const yuri& rhs) {
return (lhs.num * rhs.den == rhs.num * lhs.den);
}
friend bool operator!=(const yuri& lhs, const yuri& rhs) {
return (lhs.num * rhs.den != rhs.num * lhs.den);
}
friend bool operator<(const yuri& lhs, const yuri& rhs) {
return (lhs.num * rhs.den < rhs.num * lhs.den);
}
friend ostream& operator << (ostream &os, const yuri rhs) noexcept {
return os << (rhs.num / rhs.den);
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
static array<array<yuri<Bint>,300>,300> A{};
for(int y = 0; y < 300; y++){
A[y].fill(yuri<Bint>(1 << 30, 1));
}
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++){
int u, v, a, b;
cin >> u >> v >> a >> b;
u--, v--;
A[u][v] = min(A[u][v], yuri<Bint>(a, b));
A[v][u] = min(A[v][u], yuri<Bint>(a, b));
}
for(int i = 0; i < n; i++) A[i][i] = yuri<Bint>(0, 1);
for(int k = 0; k < n; k++){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
auto v = A[i][k] + A[k][j];
if(v < A[i][j]){
A[i][j] = v;
}
}
}
}
for(int i = 1; i < n; i++){
A[0][i].safe();
cout << A[0][i].num << ' ' << A[0][i].den << '\n';
}
}