結果

問題 No.3669 误差绝不允许
コンテスト
ユーザー butsurizuki
提出日時 2026-09-05 00:22:19
言語 C++23
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 263 ms / 3,000 ms
+ 657µs
コード長 1,045 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,628 ms
コンパイル使用メモリ 622,924 KB
実行使用メモリ 25,892 KB
最終ジャッジ日時 2026-09-05 00:22:35
合計ジャッジ時間 12,258 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using bint=boost::multiprecision::cpp_int;
using pib=pair<int,bint>;
using Graph=vector<vector<pib>>;
using pbi=pair<bint,int>;

int main() {
  bint l=1;
  for(int i=1;i<=300;i++){
    l=lcm(l,(bint)i);
  }
  // cout << l << "\n";
  int n,m;
  cin >> n >> m;
  Graph g(n);
  for(int i=0;i<m;i++){
    int u,v,a,b;
    cin >> u >> v >> a >> b;
    u--; v--;
    bint w=((bint)a);
    w*=l;
    w/=((bint)b);
    g[u].push_back({v,w});
    g[v].push_back({u,w});
  }
  bint big=l*((bint)8e18);
  vector<bint> d(n,big);
  priority_queue<pbi,vector<pbi>,greater<pbi>> pq;
  d[0]=0;
  pq.push({(bint)0,0});
  while(!pq.empty()){
    auto od=pq.top(); pq.pop();
    if(d[od.second]!=od.first){continue;}
    for(auto [v,w] : g[od.second]){
      bint nd=d[od.second]+w;
      if(d[v]>nd){
        d[v]=nd;
        pq.push({nd,v});
      }
    }
  }
  for(int i=1;i<n;i++){
    bint g=gcd(d[i],l);
    cout << (d[i]/g) << " " << (l/g) << "\n";
  }
  return 0;
}
0