#include #include using namespace std; using bint=boost::multiprecision::cpp_int; using pib=pair; using Graph=vector>; using pbi=pair; 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> 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 d(n,big); priority_queue,greater> 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