diff --git a/Medium/Day10/Solution.cpp b/Medium/Day10/Solution.cpp index 60366e5..388f86a 100644 --- a/Medium/Day10/Solution.cpp +++ b/Medium/Day10/Solution.cpp @@ -1 +1,101 @@ -// Write Yoyur Code here \ No newline at end of file +// Write Yoyur Code here + +#include +#include +#include +#include +#include +#include +#define int long long +#define f first +#define s second +#include +#define pb push_back +using namespace std; +typedef pair pii; +typedef pair piii; + +signed main() { + +ios_base::sync_with_stdio(false); +cin.tie(0); + +int t; +t=1; +while(t--){ + int n,m,k; +cin >> n >> m >> k; + +vector start[n+1]; + +for(int i=0;i> a>>b; + if(a>b) + swap(a,b); + start[a].push_back({a,b}); + start[b].push_back({b,a}); +} + + set st; + for(int i=0;i>a>>b>>c; + st.insert({{a,b},c}); + } + + queueq; + map prev; + + for(auto it:start[1]) + q.push(it),prev[it]={-1,-1}; + + + int flag=0; + pii fin; + + while(!q.empty()){ + pii cur=q.front(); + q.pop(); + if(cur.s==n){ + fin=cur; + flag=1; + break; + } + + for(auto it:start[cur.s]){ + if(st.find({cur,it.s})!=st.end()) + continue; + + if(prev.find(it)!=prev.end()) + continue; + prev[it]=cur; + q.push(it); + } + } + + if(!flag){ + cout<<-1< v; + + while(fin.f!=-1){ + v.push_back(fin.s); + fin=prev[fin]; + } + v.push_back(1); + + reverse(v.begin(),v.end()); + + + cout<