WA On #3 #4 #5

P2185 公路通行税

```cpp #include <bits/stdc++.h> #define int long long using namespace std; const int MAXN = 1005; int n, m, ans; bool visited[MAXN]; vector<int> graph[MAXN]; void bfs(int p) { queue<pair<int, int>> q; q.emplace(make_pair(p, 0)); while (!q.empty()) { int now_p = q.front().first, dis = q.front().second; q.pop(); if (visited[now_p]) { break; } else { visited[now_p] = true; } ans = max(ans, dis); for (auto e : graph[now_p]) { if (visited[e]) { continue; } q.emplace(make_pair(e, dis + 1)); } } } signed main() { while (cin >> n >> m && n + m) { ans = 0; for (int i = 1; i <= n; i ++) { graph[i].clear(); } for (int i = 1; i <= m; i ++) { int a, b; cin >> a >> b; graph[a].emplace_back(b); graph[b].emplace_back(a); } for (int i = 1; i <= n; i ++) { memset(visited, false, sizeof(visited)); bfs(i); } cout << ans * 100 << endl; } return 0; } ```
by kncjjdr05 @ 2023-01-23 12:51:41


|