답안 #941420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
941420 2024-03-08T21:15:17 Z TAhmed33 Hard route (IZhO17_road) C++
19 / 100
4 ms 604 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e2 + 25;
vector <int> adj[MAXN];
int n;
vector <int> cur; bool flag = 0;
void getPath (int a, int p, int b) {
    cur.push_back(a);
    if (a == b) {
        flag = 1;
        return;
    }
    for (auto j : adj[a]) {
        if (j == p) continue;
        getPath(j, a, b);
        if (flag) return;
    }
    cur.pop_back();
}
int main () {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector <int> dd;
    for (int i = 1; i <= n; i++) {
        if ((int)adj[i].size() == 1) {
            dd.push_back(i);
        }
    }
    int mx = 0, cnt = 0;    
    for (int i = 0; i + 1 < (int)dd.size(); i++) {
        for (int j = i + 1; j < (int)dd.size(); j++) {
            int dist[n + 1] = {};
            cur.clear(); flag = 0;
            getPath(dd[i], -1, dd[j]);
            assert(flag);
            for (int k = 1; k <= n; k++) dist[k] = 1e9;
            queue <int> dd2;
            for (auto k : cur) {
                dist[k] = 0;
                dd2.push(k);
            }
            while (!dd2.empty()) {
                auto k = dd2.front();
                dd2.pop();
                for (auto j : adj[k]) {
                    if (1 + dist[k] < dist[j]) {
                        dist[j] = 1 + dist[k];
                        dd2.push(j);
                    }
                }
            }
            int g = (int)cur.size() - 1;
            g *= *max_element(dist + 1, dist + n + 1);
            if (g == mx) cnt++;
            else if (g > mx) {
                mx = g; cnt = 1;
            }
        }
    }
    cout << mx << " " << cnt << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 472 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 4 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 472 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 4 ms 476 KB Output is correct
25 Runtime error 1 ms 604 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 472 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 4 ms 476 KB Output is correct
25 Runtime error 1 ms 604 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -