5 30 50 70 20 60 NYYNN NNYNN NNNYY YNNNN YNNNN 3 1 3 3 1 4 5
1 100 2 160 3 180 For $(S,T)=(U_1,V_1)=(1,3)$, there is a direct flight from city $1$ to city $3$, so the minimum possible number of direct flights is $1$, which is achieved when he uses that direct flight. In this case, the total value of the souvenirs is $A_1+A_3=30+70=100$. For $(S,T)=(U_2,V_2)=(3,1)$, the minimum possible number of direct flights is $2$. The following two routes achieve the minimum: cities $3\to 4\to 1$, and cities $3\to 5\to 1$. Since the total value of souvenirs in the two routes are $70+20+30=120$ and $70+60+30=160$, respectively, so he chooses the latter route, and the total value of the souvenirs is $160$. For $(S,T)=(U_3,V_3)=(4,5)$, the number of direct flights is minimum when he travels cities $4\to 1\to 3\to 5$, where the total value of the souvenirs is $20+30+70+60=180$.
2 100 100 NN NN 1 1 2
Impossible There may be no direct flight at all.
{
"problem": {
"name": "Souvenir",
"description": {
"content": "There are $N$ cities. There are also one-way direct flights that connect different cities. The availability of direct flights is represented by $N$ strings $S_1,S_2,\\ldots,S_N$ of length $N$ each. I",
"description_type": "Markdown"
},
"platform": "AtCoder",
"limit": {
"time_limit": 3000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "abc286_e"
},
"statements": [
{
"statement_type": "Markdown",
"content": "There are $N$ cities. There are also one-way direct flights that connect different cities. \nThe availability of direct flights is represented by $N$ strings $S_1,S_2,\\ldots,S_N$ of length $N$ each. I...",
"is_translate": false,
"language": "English"
}
]
}