Advertisement
Alisator

PAL3_29-10-1

Oct 29th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.11 KB | None | 0 0
  1. package pal;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.PriorityQueue;
  7. import java.util.Queue;
  8.  
  9. public class Main2 {
  10.  
  11.     //read
  12.  
  13.     static public int M; //countOfCities with gas station
  14.     static public int N; //countOfCities without gas station
  15.     static public int H; //highways
  16.     static public int F; //max distance without refueling
  17.     static public int S; //start label
  18.     static public int T; //end label
  19.     //create
  20.     static public int[][] highways; //matice sousednosti
  21.     static public int[] citiesWeight; //index odpovida label hotelu - weight for dijkstra
  22.     static public boolean[] citiesVisited; // for dijkstra
  23.     static public boolean[] citiesHasGas;
  24.     static public int countOfCities;
  25.     static public int countOfGas;
  26.     static public Queue dijkstraQ; //fronta pro uchovavani navstivenych vrcholu pro Dijkstru
  27.  
  28.     public static void main(String[] args) throws IOException {
  29.  
  30.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  31.         String[] in = br.readLine().split(" ");
  32.         M = Integer.parseInt(in[0]);
  33.         N = Integer.parseInt(in[1]);
  34.         H = Integer.parseInt(in[2]);
  35.         F = Integer.parseInt(in[3]);
  36.         S = Integer.parseInt(in[4]);
  37.         T = Integer.parseInt(in[5]);
  38.         countOfCities = M + N;
  39.         highways = new int[countOfCities][countOfCities]; //matice
  40.         dijkstraQ = new PriorityQueue();
  41.        
  42.         citiesHasGas = new boolean[countOfCities];
  43.         for (int i = 0; i < M; i++) {
  44.             int inM = Integer.parseInt(br.readLine());
  45.             citiesHasGas[inM] = true; //mesto je pumpa
  46.             countOfGas++;
  47.         }
  48.         for (int i = 0; i < H; i++) {
  49.             String[] inH = br.readLine().split(" ");
  50.             //matice sousednosti
  51.             int x = Integer.parseInt(inH[0]); //x
  52.             int y = Integer.parseInt(inH[1]); //y
  53.             highways[x][y] = Integer.parseInt(inH[2]); //na x,y delka
  54.             highways[y][x] = Integer.parseInt(inH[2]); //na x,y delka
  55.         }
  56.     }
  57.    
  58.     public static void DijkstraCreateNewGraph(int from)
  59.     {
  60.      int[] prev = new int[countOfCities];
  61.      citiesWeight = new int[countOfCities]; //index odpovida label vrcholu, weight
  62.      citiesVisited = new boolean[countOfCities];
  63.      citiesWeight[from] = 0;
  64.      for(int i = 0; i < countOfCities; i++)
  65.      {
  66.          if (i != from)
  67.          {
  68.              citiesWeight[i] = Integer.MAX_VALUE;
  69.          }
  70.          dijkstraQ.add(i);
  71.      }
  72.      while(!dijkstraQ.isEmpty())
  73.      {
  74.          int u = (int)dijkstraQ.poll();
  75.          citiesVisited[u] = true; //visited
  76.          //pro kazdyho souseda i vrcholu u
  77.          //jestli soused i nebyl navstiven
  78.             //spocitej help = citiesWeight[u] + delka mezi i a u
  79.             //jestli help < citiesWeight[i] && help < fuel
  80.                 //nastav novou delku i
  81.                 //odecti od fuel
  82.                 //prev[i] = u
  83.                 //Q.decreasekey(i)
  84.                 //jestli je to pumpa, pridej do noveho grafu
  85.      }    
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement