#include #include #include using namespace std ; typedef long long ll ; const ll INFTY = 1LL << 60 ; vector ta, tb ; vector ca, cb ; vector > perc ; vector minf ; int main() { int n, m ; cin >> n >> m ; ta.resize(m) ; tb.resize(m) ; ca.resize(m) ; cb.resize(m) ; vector > sa ; minf.resize(m) ; for (int i=0; i> ca[i] >> cb[i] >> ta[i] >> tb[i] ; sa.push_back(make_pair(tb[i], i)) ; if (ca[i] == 1) minf[i] = min(minf[i], ta[i]*ta[i]) ; } sort(sa.begin(), sa.end()) ; perc.resize(n+1) ; ll r = INFTY ; for (int i=0; i minf[pf] + (tb[pf]-ta[fi])*(tb[pf]-ta[fi])) mf = minf[pf] + (tb[pf]-ta[fi])*(tb[pf]-ta[fi]) ; } // cout << "Minimum frustration for flight " << fi << " is " << mf << endl ; minf[fi] = mf ; if (cb[fi] == n) r = min(r, mf) ; perc[cb[fi]].push_back(fi) ; } if (r >= INFTY) cout << "No route." << endl ; else cout << r << endl ; }