-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonk_and_the_hops.cpp
More file actions
73 lines (65 loc) · 1.46 KB
/
monk_and_the_hops.cpp
File metadata and controls
73 lines (65 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include<utility>
#include<vector>
#include<set>
using namespace std;
vector<int> we(100001,1000000000);
vector<bool> ve(100001,true);
vector<int> fl(100001,0);
vector<short> kl(100001,4);
void fj(int lj,int cd)
{if(kl[lj]==kl[cd] || kl[cd]==3)
fl[lj]=fl[cd];
else
fl[lj]=(fl[cd]+1);}
void dj(vector<vector<pair<int,int> > > a)
{
kl[1]=3;
multiset<pair<int,int> > s;
s.insert({0,1});
while(!s.empty())
{
pair<int,int> e=*s.begin();
s.erase(s.begin());
if(ve[e.second]==false)
continue;
ve[e.second]=false;
int xk=e.first;int cd=e.second;
for(unsigned int i=0;i<a[cd].size();i++)
{
int lj=a[cd][i].second;int bj=a[cd][i].first;
if(xk+bj<we[lj])
{kl[lj]=bj%2;
fj(lj,cd);
we[lj]=xk+bj;
s.insert({we[lj],lj});
continue;
}
else if(xk+bj==we[lj] && fl[lj]>=fl[cd])
{
if(fl[lj]>fl[cd])
{fl[lj]=bj%2;
fj(lj,cd);
continue;
}
if(bj%2!=kl[lj])
kl[lj]=3;
}
}
}}
int main()
{
int N,M;
cin>>N>>M;
vector<vector<pair<int,int> > > a(N+1);
for(int i=0;i<M;i++)
{
int b,c,d;
cin>>b>>c>>d;
a[b].push_back(make_pair(d,c));
a[c].push_back(make_pair(d,b));
}
dj(a);
cout<<we[N]<<" "<<fl[N];
return 0;
}