#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

void findShortestPathsAndFives(int n, vector<vector<int>>& adj, vector<int>& val) {
    vector<int> dist(n + 1, -1);
    vector<int> max_fives(n + 1, 0);
    
    queue<int> q;
    
    // Base Case: Start from node 1
    dist[1] = 0;
    max_fives[1] = (val[1] == 5 ? 1 : 0);
    q.push(1);
    
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        
        for (int v : adj[u]) {
            int is_five = (val[v] == 5 ? 1 : 0);
            
            // 1. First time reaching 'v' (unvisited)
            if (dist[v] == -1) {
                dist[v] = dist[u] + 1;
                max_fives[v] = max_fives[u] + is_five;
                q.push(v);
            } 
            // 2. Found an alternative shortest path to 'v'
            else if (dist[v] == dist[u] + 1) {
                // Maximize the number of 5s on the shortest path
                max_fives[v] = max(max_fives[v], max_fives[u] + is_five);
            }
        }
    }
    
    // Output the results
    for (int i = 1; i <= n; i++) {
        if (dist[i] != -1) {
            cout << "Node " << i << " -> Shortest Path: " << dist[i] 
                 << ", Max 5s: " << max_fives[i] << "\n";
        } else {
            cout << "Node " << i << " -> Unreachable\n";
        }
    }
}
int main(){}