707B Codeforces - Bakery - Solution





Solution in c++

#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int n,m,k,t1,t2,t3,mn=-1;
vector<pair<int,int> > adj[100005];
vector<int> sto(100005),ston;

dfs_one_step(int n){

for(auto u:adj[n]){if((!sto[u.first] && (u.second<mn || mn==-1)) )mn=u.second;}

}

int main()
{
    cin>>n>>m>>k;
    while(m--){

        cin>>t1>>t2>>t3;
        adj[t1].push_back(make_pair(t2,t3));
        adj[t2].push_back(make_pair(t1,t3));
    }
    while(k--){
        cin>>t1;
        ston.push_back(t1);
        sto[t1]++;
    }
    
for(auto au: ston)dfs_one_step(au);
   
   
 cout<<mn;


    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق