Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pal;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.PriorityQueue;
- import java.util.Queue;
- public class Main2 {
- //read
- static public int M; //countOfCities with gas station
- static public int N; //countOfCities without gas station
- static public int H; //highways
- static public int F; //max distance without refueling
- static public int S; //start label
- static public int T; //end label
- //create
- static public int[][] highways; //matice sousednosti
- static public int[] citiesWeight; //index odpovida label hotelu - weight for dijkstra
- static public boolean[] citiesVisited; // for dijkstra
- static public boolean[] citiesHasGas;
- static public int countOfCities;
- static public int countOfGas;
- static public Queue dijkstraQ; //fronta pro uchovavani navstivenych vrcholu pro Dijkstru
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String[] in = br.readLine().split(" ");
- M = Integer.parseInt(in[0]);
- N = Integer.parseInt(in[1]);
- H = Integer.parseInt(in[2]);
- F = Integer.parseInt(in[3]);
- S = Integer.parseInt(in[4]);
- T = Integer.parseInt(in[5]);
- countOfCities = M + N;
- highways = new int[countOfCities][countOfCities]; //matice
- dijkstraQ = new PriorityQueue();
- citiesHasGas = new boolean[countOfCities];
- for (int i = 0; i < M; i++) {
- int inM = Integer.parseInt(br.readLine());
- citiesHasGas[inM] = true; //mesto je pumpa
- countOfGas++;
- }
- for (int i = 0; i < H; i++) {
- String[] inH = br.readLine().split(" ");
- //matice sousednosti
- int x = Integer.parseInt(inH[0]); //x
- int y = Integer.parseInt(inH[1]); //y
- highways[x][y] = Integer.parseInt(inH[2]); //na x,y delka
- highways[y][x] = Integer.parseInt(inH[2]); //na x,y delka
- }
- }
- public static void DijkstraCreateNewGraph(int from)
- {
- int[] prev = new int[countOfCities];
- citiesWeight = new int[countOfCities]; //index odpovida label vrcholu, weight
- citiesVisited = new boolean[countOfCities];
- citiesWeight[from] = 0;
- for(int i = 0; i < countOfCities; i++)
- {
- if (i != from)
- {
- citiesWeight[i] = Integer.MAX_VALUE;
- }
- dijkstraQ.add(i);
- }
- while(!dijkstraQ.isEmpty())
- {
- int u = (int)dijkstraQ.poll();
- citiesVisited[u] = true; //visited
- //pro kazdyho souseda i vrcholu u
- //jestli soused i nebyl navstiven
- //spocitej help = citiesWeight[u] + delka mezi i a u
- //jestli help < citiesWeight[i] && help < fuel
- //nastav novou delku i
- //odecti od fuel
- //prev[i] = u
- //Q.decreasekey(i)
- //jestli je to pumpa, pridej do noveho grafu
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement