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 61 62 63 64 65 66 67 68 69 70 71 `#include #include #include #include #include using namespace std; const int MAX_N=100007; int n, q, a, b, act_city; long long c, act; long long z[MAX_N]; vector pol[MAX_N]; pair out; map , long long> cost; bool visited[MAX_N]; void dfs(int from, int now) { visited[now]=1; if(now!=from) { if(act+z[now]>out.first) { out.first=act+z[now]; out.second=now; } else if(act+z[now]==out.first && now