From 2ab59abe211db3aaac75c8c3b38a7e92c6d5f834 Mon Sep 17 00:00:00 2001 From: Viraj Shah Date: Sat, 25 Apr 2015 18:39:42 -0400 Subject: [PATCH] UVaOJ --- 10986 - Sending email/SendingEmail.cpp | 75 ++++++++++++++++++ 315 - Network/Network.cpp | 105 +++++++++++++++++++++++++ README.md | 14 +++- 3 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 10986 - Sending email/SendingEmail.cpp create mode 100644 315 - Network/Network.cpp diff --git a/10986 - Sending email/SendingEmail.cpp b/10986 - Sending email/SendingEmail.cpp new file mode 100644 index 0000000..dff8d32 --- /dev/null +++ b/10986 - Sending email/SendingEmail.cpp @@ -0,0 +1,75 @@ +/* + * SendingEmail.cpp + * + * Created on: Apr 25, 2015 + * Author: viraj + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define INF 1000000000 + +using namespace std; +vector val; +vector > > neighbors; +int t,n,m,s,x,y,v; + +void dijkstras(int s,int t){ + priority_queue,vector >,greater > > pq; + pq.push(pair(s,0)); + val[s]=0; + while(!pq.empty()){ + pair top = pq.top(); + pq.pop(); + for(int j=0;j x = neighbors[top.first][j]; + if(val[x.first]>x.second+val[top.first]){ + val[x.first]=x.second+val[top.first]; + pq.push(make_pair(x.first,val[x.first])); + } + } + } +} + + +int main(){ + int cases; + scanf("%d",&cases); + for(int i=1;i<=cases;++i){ + scanf("%d %d %d %d",&n,&m,&s,&t); + val = vector(n,INF); + neighbors = vector > > (n,vector >()); + while(m--){ + scanf("%d %d %d",&x,&y,&v); + neighbors[x].push_back(make_pair(y,v)); + neighbors[y].push_back(make_pair(x,v)); + } + dijkstras(s,t); + if(val[t]==INF){ + cout<<"Case #"< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define INF 1000000000 + +using namespace std; + +vector > neighbors; +vector visited; +int nodes; + +int getvisitedtotal(){ + int total=0; + for(int i=0;i (nodes,false); + stack st; + st.push(source); + while(!st.empty()){ + int node = st.top(); + st.pop(); + visited[node]=true; + for(int j=0;j > (nodes,vector ()); + string temp; + while(getline(cin,temp)){ + if(temp=="0"){ + break; + } + //cout<> source; + int neighbor; + while(ss >> neighbor){ + neighbors[source-1].push_back(neighbor-1); + neighbors[neighbor-1].push_back(source-1); + } + } + int ans=0; + for(int i=0;i