文件目录

    #include <bits/stdc++.h>
    using namespace std;
    int n, m, a, b, x, y;
    int v[100005];
    vector<int> e[100005];
    int f[100005];
    void bfs(int s)
    {
        memset(f, 0x3f, sizeof(f));
        queue<int> q;
        q.push(s);
        f[s] = 0;
        while (!q.empty())
        {
            int u = q.front();
            q.pop();
            for (int i = 0; i < e[u].size(); i++)
            {
                int v = e[u][i];
                if (f[v] > f[u] + 1)
                {
                    f[v] = f[u] + 1;
                    q.push(v);
                }
            }
        }
    }
    int main()
    {
        scanf("%d %d %d %d", &n, &m, &a, &b);
        for (int i = 0; i < n; i++)
            scanf("%d", v + i);
        for (int i = 0; i < m; i++)
        {
            scanf("%d %d", &x, &y);
            e[x].push_back(y);
        }
        bfs(a);
        if (f[b] == f[n])
            cout << "No solution";
        else
            cout << f[b] + v[b] - v[a];
        return 0;
    }