标签:des style blog http color java os io
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 667 Accepted Submission(s): 271
#include <iostream> #include <stack> #include <cstring> #include <cstdio> #include <string> #include <algorithm> #include <queue> using namespace std; /* 要求出某个点到所有公交站点的距离最大的最小; 那么就可以先求出每个公交站点到所有点的距离中,相应的每个点到公交站点的距离取最大,在所有点距离去最小即可。 */ #define ms(arr, val) memset(arr, val, sizeof(arr)) #define N 10000 #define INF 0x3fffffff struct node { int seq; int lay; }; int id[N][11]; int idtag[N]; int idmax[N]; int iddis[N]; queue<int> q; void bfs(int p)//求bfs求单元最短路,因为相邻两点距离为1. { ms(iddis, 0); ms(idtag, 0); q.push(p); idtag[p] = iddis[p] = 1; while (!q.empty()) { int s = q.front(); q.pop(); int i = 0; while (id[s][i]) { if (!idtag[id[s][i]]) { iddis[id[s][i]] = iddis[s] + 1; idtag[id[s][i]] = 1; q.push(id[s][i]); } i++; } } } int main() { int t, nz, nr, mzn, idp, mrn, tt, ans, pos; cin >> t; while (t--) { ms(id, 0); ms(idmax, 0); cin >> nz >> nr; for (int i = 0; i < nz; i++) { cin >> idp >> mzn; for (int j = 0; j < mzn; j++) { cin >> id[idp][j]; } } for (int i = 0; i < nr; i++) { cin >> mrn; for (int j = 0; j < mrn; j++) { cin >> tt; bfs(tt); for (int i = 0; i < N; i++) { idmax[i] = max(idmax[i], iddis[i]); } } } pos = 0; ans = INF; for (int i = 0; i < N; i++) { if (idmax[i] > 0 && ans > idmax[i]) { pos = i; ans = idmax[i]; } } cout << ans <<‘ ‘<<pos<< endl; } return 0; }
hdu 2377 Bus Pass,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/jecyhw/p/3897510.html