1. Abridged Problem Statement  
Given a directed graph with N towns (vertices) and M one-way routes (edges). Each edge from u to v has a cost C and a time T. Find a simple directed cycle (length ≥2) that maximizes the ratio (sum of costs)/(sum of times). If no cycle exists, output 0. Otherwise, output the number of towns in the cycle followed by the sequence of towns in order.

2. Detailed Editorial  

Goal  
We want a cycle G that maximizes  
    F(G) = (Σ cost on G)/(Σ time on G).  

Observation  
This is the classic “maximum mean weight cycle” problem on a directed graph, where each edge e has weight w(e) = cost(e) - λ·time(e). If, for a given λ, there is a cycle whose total modified weight is positive, then its original cost/time ratio exceeds λ. We can binary‐search λ and detect positive‐weight cycles in the modified graph.

Reformulation  
Define for any candidate ratio x:  
    modified_weight(e) = cost(e) - x·time(e).  
A cycle has average cost/time > x exactly when the sum of modified_weight over that cycle is > 0.

Cycle detection by Bellman-Ford  
To test whether any positive‐weight cycle exists, we can negate the weights and run standard Bellman‐Ford to detect negative cycles. Concretely we set  
    w'(e) = x·time(e) - cost(e),  
so a negative cycle in w' corresponds to a cycle of mean cost/time > x.

Algorithm Steps  
1. Read n, m and all edges (u, v, cost, time).  
2. Binary‐search x over an interval that surely contains the optimum ratio (e.g., [0, 200]).  
3. For each mid = (lo + hi)/2:  
   a. Build w'(e) = mid·time(e) - cost(e).  
   b. Add a super‐source connected to every node with zero‐weight edges.  
   c. Run Bellman‐Ford for n iterations; if any distance can still be relaxed in the nth pass, a negative cycle exists. Record parent pointers.  
   d. If a negative cycle exists, set lo = mid; else hi = mid.  
4. After ~60–100 iterations, lo≈max ratio. Re‐run the Bellman‐Ford check at x=lo to recover one negative cycle.  
5. Extract the cycle by following parent pointers n steps from one node on the detected cycle to ensure landing inside the cycle, then traverse parents until we close the loop.  
6. Output the cycle’s size and the sequence of towns. If none found, output 0.

Complexity  
Binary‐search iterations: ~100.  
Each Bellman‐Ford: O(n·m).  
Total: O(100·n·m), which is fine for n≤50, m≤2500.

3. C++ Solution

```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

struct Edge {
    int u, v, c, t;
};

int n, m;
vector<Edge> edges;
vector<double> dist;
vector<int> par;

void read() {
    cin >> n >> m;
    edges.resize(m);
    for(int i = 0; i < m; i++) {
        cin >> edges[i].u >> edges[i].v >> edges[i].c >> edges[i].t;
    }
}

pair<bool, vector<int>> check(double x) {
    dist.assign(n + 2, 1e18);
    par.assign(n + 2, -1);

    int source = n + 1;
    dist[source] = 0;

    for(int i = 0; i < n; i++) {
        for(auto& e: edges) {
            double weight = e.t * x - e.c;
            if(dist[e.u] < 1e17 && dist[e.u] + weight < dist[e.v]) {
                dist[e.v] = dist[e.u] + weight;
                par[e.v] = e.u;
            }
        }

        for(int v = 1; v <= n; v++) {
            if(dist[source] < dist[v]) {
                dist[v] = dist[source];
                par[v] = source;
            }
        }
    }

    int cycle_node = -1;
    for(auto& e: edges) {
        double weight = e.t * x - e.c;
        if(dist[e.u] < 1e17 && dist[e.u] + weight < dist[e.v]) {
            cycle_node = e.v;
            break;
        }
    }

    if(cycle_node == -1) {
        return {false, {}};
    }

    for(int i = 0; i < n; i++) {
        cycle_node = par[cycle_node];
    }

    vector<int> cycle;
    int curr = cycle_node;
    do {
        cycle.push_back(curr);
        curr = par[curr];
    } while(curr != cycle_node);

    reverse(cycle.begin(), cycle.end());
    return {true, cycle};
}

void solve() {
    // We maximize the cycle ratio (sum of costs) / (sum of times). Binary search
    // the answer x: a cycle with ratio > x exists iff some cycle has positive
    // sum of (c - t*x), equivalently a negative cycle under edge weight
    // t*x - c. We detect such a cycle with N relaxation rounds of Bellman-Ford
    // from a virtual super-source connected to every node, then one extra round
    // to find an edge that still relaxes; walking N parent steps lands inside the
    // negative cycle, which we trace via the parent array and report.

    double l = 0.0, r = 200.0;
    for(int i = 0; i < 100; i++) {
        double mid = (l + r) / 2;
        auto [has_cycle, cycle] = check(mid);
        if(has_cycle) {
            l = mid;
        } else {
            r = mid;
        }
    }

    auto [has_cycle, cycle] = check(l);
    if(!has_cycle) {
        cout << "0\n";
        return;
    }

    cout << cycle.size() << "\n";
    cout << cycle << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

4. Python Solution with Detailed Comments  

```python
import sys
sys.setrecursionlimit(10**7)

def readints():
    return map(int, sys.stdin.readline().split())

def find_cycle(n, edges, x):
    """
    Run Bellman-Ford to detect a negative cycle under weights w' = x*t - c.
    Returns (has_cycle, list_of_nodes_in_cycle).
    """
    INF = 1e18
    dist = [INF] * (n + 2)
    par  = [-1]  * (n + 2)
    source = n + 1
    dist[source] = 0.0

    # Relax edges n times
    for _ in range(n):
        # Relax real edges
        for u, v, c, t in edges:
            w = x*t - c
            if dist[u] + w < dist[v]:
                dist[v] = dist[u] + w
                par[v] = u
        # Relax super-source → every node
        for v in range(1, n+1):
            if dist[source] < dist[v]:
                dist[v] = dist[source]
                par[v] = source

    # One extra pass to detect a negative cycle
    cycle_node = -1
    for u, v, c, t in edges:
        w = x*t - c
        if dist[u] + w < dist[v]:
            cycle_node = v
            break

    if cycle_node == -1:
        return False, []

    # Walk back n steps to ensure inside the cycle
    for _ in range(n):
        cycle_node = par[cycle_node]

    # Reconstruct cycle
    cycle = []
    curr = cycle_node
    while True:
        cycle.append(curr)
        curr = par[curr]
        if curr == cycle_node:
            break
    cycle.reverse()
    return True, cycle

def main():
    data = sys.stdin.read().split()
    it = iter(data)
    n, m = map(int, (next(it), next(it)))
    edges = []
    for _ in range(m):
        u, v, c, t = map(int, (next(it), next(it), next(it), next(it)))
        edges.append((u, v, c, t))

    lo, hi = 0.0, 200.0
    # Binary search for ~80–100 iterations
    for _ in range(80):
        mid = (lo + hi) / 2.0
        has, _ = find_cycle(n, edges, mid)
        if has:
            lo = mid
        else:
            hi = mid

    # Recover the cycle at best ratio lo
    has, cycle = find_cycle(n, edges, lo)
    if not has:
        print(0)
    else:
        print(len(cycle))
        print(" ".join(map(str, cycle)))

if __name__ == "__main__":
    main()
```

5. Compressed Editorial  

- We seek a directed cycle maximizing (∑cost)/(∑time).  
- Equivalently, for λ, check if there’s a cycle with ∑(cost − λ·time) > 0.  
- Negate to weights w' = λ·time − cost; detect negative cycles by Bellman‐Ford.  
- Binary‐search λ in [0,200] to precision.  
- On finding a negative cycle at final λ, reconstruct it using parent pointers.