n, m; scanf(“%d%d”,&n,&m); vector<int> to[1005]; for(int i = 0; i < m; i++){ int v, u; scanf(“%d%d”,&v,&u); to[v].push_back(u); } int dist[1005]; for(int i = 0; i < n; i++) dist[i] = 1000000000; dist[0] = 0; for(int v = 0; v < n; v++){ for(int i = 0; i < to[v].size(); i++){ int u = to[v][i]; dist[u] = min(dist[u], dist[v]+1); } } printf(“%d\n”,dist[n-1]); return 0; } #include<cstdio> #include<vector> #include<algorithm> using namespace std; int main(){ int n, m; scanf(“%d%d”,&n,&m); vector<int> to[1005]; for(int i = 0; i < m; i++){ int v, u; scanf(“%d%d”,&v,&u); to[v].push_back(u); } int count[1005]; for(int i = 0; i < n; i++) count[i] = 0; count[0] = 1; for(int v = 0; v < n; v++){ for(int i = 0; i < to[v].size(); i++){ int u = to[v][i]; count[u] = (count[u]+count[v])%1000000009; } } printf(“%d\n”,count[n-1]); return 0; } 最短距離 経路の数