結果
| 問題 | No.3669 误差绝不允许 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-04 22:53:22 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 8,097 bytes |
| 記録 | |
| コンパイル時間 | 4,111 ms |
| コンパイル使用メモリ | 388,140 KB |
| 実行使用メモリ | 12,760 KB |
| 最終ジャッジ日時 | 2026-09-04 23:03:03 |
| 合計ジャッジ時間 | 11,392 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge5_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 13 WA * 1 TLE * 1 -- * 15 |
ソースコード
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define vi vector<int>
#define vl vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vc vector<char>
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
template<class T, class U>
inline bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<class T, class U>
inline bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
// #define ll int
// #define ll int128_t
// #define ll int256_t
// #define ll cpp_int
constexpr ll inf = (1ll << 62);
// constexpr ll inf = (1 << 30);
// const double PI=3.1415926535897932384626433832795028841971;
uint32_t xor_x = 123456789, xor_y = 362436069, xor_z = 521288629, xor_w = 88675123;
inline uint32_t xor_next() {
uint32_t t = xor_x ^ (xor_x << 11);
xor_x = xor_y; xor_y = xor_z; xor_z = xor_w;
return xor_w = (xor_w ^ (xor_w >> 19)) ^ (t ^ (t >> 8));
}
inline int rnd(int max_val) { return xor_next() % max_val; }
struct Timer {
std::chrono::steady_clock::time_point start_time;
Timer() {
reset();
}
// 測定の起点リセット用
void reset() {
start_time = std::chrono::steady_clock::now();
}
// スタートからの経過時間をミリ秒(msec)で返す
long long get_ms() const {
auto now = std::chrono::steady_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(now - start_time).count();
}
};
// ll rui(ll a,ll b){
// if(b==0)return 1;
// if(b%2==1) return a*rui(a*a,b/2);
// return rui(a*a,b/2);
// }
// vl fact;
// ll kai(ll n){
// fact.resize(n,1);
// rep(i,n-1)fact[i+1]=fact[i]*(i+1);
// }
// using mint = ld;
// using mint = modint998244353;//static_modint<998244353>
// using mint = modint1000000007;//static_modint<1000000007>
// using mint = static_modint<922267487>; // 多分落とされにくい NOT ntt-friendly
// using mint = static_modint<469762049>; // ntt-friendly
// using mint = static_modint<167772161>; // ntt-friendly
// using mint = modint;//mint::set_mod(mod);
// ll const mod=1000000007ll;
// ll const mod=998244353ll;
// ll modrui(ll a,ll b,ll mod){
// a%=mod;
// if(b==0)return 1;
// if(b%2==1) return a*modrui(a*a%mod,b/2,mod)%mod;
// return modrui(a*a%mod,b/2,mod)%mod;
// }
// void incr(vl &v,ll n){// n進法
// ll k=v.size();
// v[k-1]++;
// ll now=k-1;
// while (v[now]>=n)
// {
// v[now]=0;
// if(now==0)break;
// v[now-1]++;
// now--;
// }
// return;
// }
// vector<mint> fact,invf;
// void init_modfact(ll sz){
// fact.resize(sz);
// invf.resize(sz);
// fact[0]=1;
// rep(i,sz-1){
// fact[i+1]=fact[i]*(i+1);
// }
// invf[sz-1]=1/fact[sz-1];
// for(ll i=sz-2; i>=0; i--){
// invf[i]=invf[i+1]*(i+1);
// }
// }
// mint choose(ll n,ll r){
// if(n<r || r<0 || n<0)return 0;
// return fact[n]*invf[r]*invf[n-r];
// }
// vector<mint> modpow,invpow;
// void init_modpow(ll x,ll sz){
// mint inv=1/mint(x);
// modpow.assign(sz,1);
// invpow.assign(sz,1);
// rep(i,sz-1){
// modpow[i+1]=modpow[i]*x;
// invpow[i+1]=invpow[i]*inv;
// }
// }
// long long phi(long long n) {// O(sqrt(n))
// long long res = n;
// for (long long i = 2; i * i <= n; i++) {
// if (n % i == 0) {
// res -= res / i;
// while (n % i == 0) n /= i;
// }
// }
// if (n > 1) res -= res / n;
// return res;
// }
// https://atcoder.jp/contests/abc244/submissions/73762024
// 有理数
struct yuri {
long long bunsi; // 分子
long long bunbo; // 分母
// コンストラクタ: 引数を __int128_t で受けるのが最大のポイント。
// 四則演算で発生した巨大な数を受け止め、約分してから long long に安全に落とし込む。
yuri(__int128_t si = 0, __int128_t bo = 1) {
assert(bo != 0); // ゼロ除算を検知してREを出させる(デバッグ用)
// 分母は常に正に保つ(比較演算をバグらせないため)
if (bo < 0) {
si = -si;
bo = -bo;
}
// __int128_t 用のユークリッド互除法
__int128_t a = si < 0 ? -si : si;
__int128_t b = bo;
while (b) {
__int128_t temp = a % b;
a = b;
b = temp;
}
bunsi = (long long)(si / a);
bunbo = (long long)(bo / a);
}
// --- 比較演算子 ---
// ここも比較の瞬間のクロス掛け算で long long を突破するのでキャスト必須
bool operator<(const yuri& rhs) const {
return (__int128_t)bunsi * rhs.bunbo < (__int128_t)rhs.bunsi * bunbo;
}
bool operator>(const yuri& rhs) const { return rhs < *this; }
bool operator<=(const yuri& rhs) const { return !(*this > rhs); }
bool operator>=(const yuri& rhs) const { return !(*this < rhs); }
bool operator==(const yuri& rhs) const {
// コンストラクタで必ず約分&分母正化されるため、単純比較でOK
return bunsi == rhs.bunsi && bunbo == rhs.bunbo;
}
bool operator!=(const yuri& rhs) const { return !(*this == rhs); }
// --- 四則演算 ---
// 計算前に __int128_t にキャストして渡し、コンストラクタ内で約分させる
yuri operator+(const yuri& rhs) const {
return yuri((__int128_t)bunsi * rhs.bunbo + (__int128_t)rhs.bunsi * bunbo, (__int128_t)bunbo * rhs.bunbo);
}
yuri operator-(const yuri& rhs) const {
return yuri((__int128_t)bunsi * rhs.bunbo - (__int128_t)rhs.bunsi * bunbo, (__int128_t)bunbo * rhs.bunbo);
}
yuri operator*(const yuri& rhs) const {
return yuri((__int128_t)bunsi * rhs.bunsi, (__int128_t)bunbo * rhs.bunbo);
}
yuri operator/(const yuri& rhs) const {
return yuri((__int128_t)bunsi * rhs.bunbo, (__int128_t)bunbo * rhs.bunsi);
}
// --- ユーティリティ ---
friend yuri abs(const yuri& a) {
return yuri(a.bunsi < 0 ? -a.bunsi : a.bunsi, a.bunbo);
}
// cout で直接出力できるようにするオーバーロード
friend std::ostream& operator<<(std::ostream& os, const yuri& a) {
if (a.bunbo == 1) os << a.bunsi;
else os << a.bunsi << "/" << a.bunbo;
return os;
}
};
void solve(){
ll n,m;
cin >> n >> m;
vector g(n,vector<pair<ll,yuri>>());
rep(i,m){
ll u,v,a,b;
cin >> u >> v >> a >> b;
u--;
v--;
g[u].push_back({v,yuri(a,b)});
g[v].push_back({u,yuri(a,b)});
}
vector<yuri> dist(n,yuri(inf,1));
dist[0]=yuri{0,1};
priority_queue<pair<yuri,ll>,vector<pair<yuri,ll>>,greater<pair<yuri,ll>>> pq;
pq.push({yuri{0,1},0});
while(!pq.empty()){
auto [d,x]=pq.top();
pq.pop();
if(dist[x]!=d)continue;
for(auto [to,cost]:g[x]){
if(chmin(dist[to],d+cost)){
pq.push({dist[to],to});
}
}
}
rep(i,n){
if(i!=0){
cout << dist[i].bunsi << " " << dist[i].bunbo << endl;
}
}
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
// ll mx=450;
// vc fl(mx+1,0);
// for(ll d=2;d<=mx;d++){
// if(fl[d])continue;
// ll x=d;
// ps.push_back(x);
// while(x<=mx){
// fl[x]=1;
// x+=d;
// }
// }
ll t = 1;
// cin >> t;
while (t--){
solve();
}
}