-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMessage Route
More file actions
60 lines (54 loc) · 1.09 KB
/
Message Route
File metadata and controls
60 lines (54 loc) · 1.09 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
//g++ 5.4.0
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
const int nax = 1e5+5;
vector<int > g[nax] , par(nax,0);
signed main()
{
fast ;
int n , m ;
cin >> n >> m ;
for(int i=0 ; i<m ; i++ )
{
int u , v;
cin >> u >> v ;
g[u].pb(v);
g[v].pb(u);
}
queue < int > q;
q.push( 1 );
par[1] = -1;
while( !q.empty() )
{
int p = q.front() ;
q.pop();
if( p == n ) break;
for( auto &i : g[p] )
if( !par[i] ) par[i] = p , q.push( i );
}
if( par[n] )
{
stack<int> s;
s.push( n );
int p = par[n] ;
while( p != -1 )
{
s.push( p );
p = par[p];
}
cout << (int)(s.size() ) << "\n";
while( !s.empty() )
{
cout << s.top() << " " ;
s.pop();
}
}
else
cout << "IMPOSSIBLE";
}