Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- int main()
- {
- int n,x,y,p,po;
- map<int,map<int,int> > graph;
- map<int,int> ch;
- vector<char> car;
- char ca,ti;
- while(cin>>n&&n!=0)
- {
- graph.clear();
- ch.clear();
- car.clear();
- po=0;
- for(int i=0;i<n;i++)
- {
- cin>>ca>>ti>>x>>y>>p;
- if(ch[x]==0)
- {
- ch[x]=po;
- po++;
- car.push_back(x);
- }
- if(ch[y]==0)
- {
- ch[y]=po;
- po++;
- car.push_back(x);
- }
- graph[ch[x]][ch[y]]=p;
- if(ca=='B')
- graph[ch[y]][ch[x]]=p;
- }
- for(int k=0;k<po;k++)
- {
- for(int i=0;i<po;i++)
- {
- for(int j=0;j<po;j++)
- {
- if(graph[i].find(k)!=graph[i].end()&&graph[k].find(j)!=graph[k].end())
- {
- if(graph[i].find(j)!=graph[i].end())
- {
- graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
- }
- else
- graph[i][j]=graph[i][k]+graph[k][j];
- }
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement