#include <iostream>
#include <vector>
#include <climits>
#define INF INT_MAX
using namespace std;
// Function to implement Floyd-Warshall algorithm to calculate shortest paths between all pairs of nodes
void floydWarshall(vector<vector<int>>& graph, int n) {
vector<vector<int>> dist = graph;
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (dist[i][k] != INF && dist[k][j] != INF && dist[i][k] + dist[k][j] < dist[i][j]) {
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
cout << "Shortest path matrix using Floyd-Warshall algorithm:" << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (dist[i][j] == INF)
cout << "INF ";
else
cout << dist[i][j] << " ";
}
cout << endl;
}
}
// Function to adjust traffic light timings based on vehicle waiting counts
void adjustTrafficLights(vector<int>& vehicleCounts, int n) {
vector<int> timings(n);
// Adjust timings based on vehicle count (proportional adjustment)
int totalVehicles = 0;
for (int count : vehicleCounts) {
totalVehicles += count;
}
for (int i = 0; i < n; ++i) {
timings[i] = (vehicleCounts[i] * 60) / totalVehicles; // Proportionally distribute 60 seconds
}
cout << "Adjusted traffic light timings (in seconds):" << endl;
for (int i = 0; i < n; ++i) {
cout << "Traffic light " << i + 1 << ": " << timings[i] << " seconds" << endl;
}
}
int main() {
int n;
cout << "Enter the number of intersections: ";
cin >> n;
vector<vector<int>> graph(n, vector<int>(n, INF));
cout << "Enter the adjacency matrix for the road network (use " << INF << " for no direct path):" << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> graph[i][j];
if (i == j) graph[i][j] = 0; // Distance to self is 0
}
}
floydWarshall(graph, n);
vector<int> vehicleCounts(n);
cout << "Enter the number of vehicles waiting at each intersection:" << endl;
for (int i = 0; i < n; ++i) {
cin >> vehicleCounts[i];
}
adjustTrafficLights(vehicleCounts, n);
return 0;
}