Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- #include <vector>
- #include <algorithm>
- #include <queue>
- #include <map>
- #include <set>
- #include <cstring>
- #include <utility>
- #include <iomanip>
- #define ll long long
- #define pb push_back
- #define INF 2e9 + 10
- #define PI acos(-1.0)
- #define LL_INF 4e17
- #define EPS 1e-9
- const int MOD = 1e9 + 7;
- const int MAXN = 1e5 + 5;
- using namespace std;
- void fileIO(string prob) {
- freopen((prob + ".in").c_str(), "r", stdin);
- freopen((prob + ".out").c_str(), "w", stdout);
- }
- void fastIO() {
- cin.tie(0)->sync_with_stdio(0);
- }
- // ..... glhf ^-^ .....//
- int n, m;
- vector<int> adj[100005];
- vector<int> radj[100005];
- int len[100005], pre[100005];
- void dfs(int par, int v, int leng) {
- len[v] = max(len[v], leng);
- pre[v] = par;
- for(int u : adj[v]) {
- if(len[v] + 1 > len[u]) dfs(v, u, leng + 1);
- }
- }
- int main() {
- cin>>n>>m;
- while(m--) {
- int a, b; cin>>a>>b;
- adj[a].pb(b);
- radj[b].pb(a);
- }
- dfs(-1, 1, 0);
- if(len[n] == 0) {
- cout<<"IMPOSSIBLE";
- return 0;
- }
- int nd = n;
- vector<int> ans;
- for(int i=n ; i != -1 ; i = pre[i]) ans.pb(i);
- cout<<ans.size()<<'\n';
- for(int i=ans.size()-1 ; i>=0 ; i--) {
- cout<<ans[i]<<" ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement