Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.    int n,x,y,p,po;
  10.    map<int,map<int,int> > graph;
  11.    map<int,int> ch;
  12.    vector<char> car;
  13.    char ca,ti;
  14.    while(cin>>n&&n!=0)
  15.    {
  16.        graph.clear();
  17.        ch.clear();
  18.        car.clear();
  19.        po=0;
  20.        for(int i=0;i<n;i++)
  21.        {
  22.            cin>>ca>>ti>>x>>y>>p;
  23.            if(ch[x]==0)
  24.            {
  25.                ch[x]=po;
  26.                po++;
  27.                car.push_back(x);
  28.            }
  29.            if(ch[y]==0)
  30.            {
  31.                ch[y]=po;
  32.                po++;
  33.                car.push_back(x);
  34.            }
  35.            graph[ch[x]][ch[y]]=p;
  36.            if(ca=='B')
  37.             graph[ch[y]][ch[x]]=p;
  38.        }
  39.        for(int k=0;k<po;k++)
  40.        {
  41.            for(int i=0;i<po;i++)
  42.            {
  43.                for(int j=0;j<po;j++)
  44.                {
  45.                    if(graph[i].find(k)!=graph[i].end()&&graph[k].find(j)!=graph[k].end())
  46.                    {
  47.                        if(graph[i].find(j)!=graph[i].end())
  48.                        {
  49.                            graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
  50.                        }
  51.                        else
  52.                         graph[i][j]=graph[i][k]+graph[k][j];
  53.                    }
  54.                }
  55.            }
  56.        }
  57.  
  58.    }
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement