/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 96ms 14.57 MiB
#3 Accepted 97ms 14.512 MiB
#4 Accepted 103ms 14.645 MiB
#5 Accepted 98ms 14.496 MiB
#6 Accepted 95ms 14.578 MiB
#7 Wrong Answer 96ms 14.637 MiB
#8 Wrong Answer 96ms 14.695 MiB
#9 Wrong Answer 97ms 14.5 MiB
#10 Wrong Answer 100ms 14.684 MiB
#11 Accepted 97ms 14.652 MiB
#12 Accepted 99ms 14.723 MiB
#13 Accepted 100ms 14.707 MiB
#14 Wrong Answer 103ms 14.746 MiB
#15 Accepted 101ms 14.637 MiB
#16 Wrong Answer 101ms 14.746 MiB
#17 Wrong Answer 100ms 14.727 MiB
#18 Wrong Answer 98ms 14.633 MiB
#19 Wrong Answer 101ms 14.742 MiB
#20 Wrong Answer 99ms 14.738 MiB
#21 Wrong Answer 1ms 324.0 KiB
#22 Wrong Answer 2ms 456.0 KiB
#23 Wrong Answer 62ms 18.281 MiB
#24 Accepted 61ms 18.156 MiB
#25 Wrong Answer 1ms 320.0 KiB
#26 Wrong Answer 22ms 3.812 MiB

Code

// #pragma GCC optimize("Ofast")
// #include <bits/stdc++.h>
// using namespace std;
// using ll = long long;
// const int MOD = 1000000007;
// #define sz(x) (ll)(x).size()
// #define rd ({ll x; cin >> x; x; })
// #define dbg(x) cerr << "[" #x "]  " << (x) << "\n\n"
// // #define errv(x) {cerr << "["#x"]  ["; for (const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
// // #define errvn(x, n) {cerr << "["#x"]  ["; for (auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
// // #define cerr \
// //     if (0)   \
// //     cerr
// #define xx first
// #define yy second
// mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
// /*_________________________________________________________________________________________________________________________*/

// #define pii pair<ll, ll>
// vector<pair<pii, pii>> out;
// struct cNode {
//     ll u;
//     pair<pii, pii> len;
// };
// pair<pii, pii> dfs(vector<cNode> adj[], ll node, ll par)
// {
//     cerr << node << "<---" << par << "\n";
//     // cerr << node << endl;
//     if ((out[node].xx.yy != par || out[node].yy.yy != par) && out[node].xx.yy != 0 && out[node].yy.yy != 0)
//         return out[node];
//     pair<pii, pii> newLen = { { 0, 0 }, { 0, 0 } };
//     set<pii, greater<pii>> st;
//     for (cNode& it : adj[node]) {
//         if (it.u == par)
//             continue;
//         it.len = dfs(adj, it.u, node);
//         if (it.len.xx.yy != node)
//             st.insert({ it.len.xx.xx + 1, it.u });
//         if (it.len.yy.yy != node)
//             st.insert({ it.len.yy.xx + 1, it.u });
//     }
//     if (st.size() == 1) {
//         auto it = st.begin();
//         newLen.xx = *it;
//     } else if (st.size() > 1) {
//         auto it = st.begin();
//         newLen.xx = *it++;
//         newLen.yy = *it;
//     }
//     return out[node] = newLen;
//     // return newLen;
// }
// void Solve()
// {
//     ll n;
//     cin >> n;
//     // dbg(1);
//     out = vector<pair<pii, pii>>(n + 1, { { 0, 0 }, { 0, 0 } });
//     // return;
//     vector<cNode> adj[n + 1];
//     // dbg(1);
//     for (int i = 0; i < n - 1; i++) {
//         ll u, v;
//         cin >> u >> v;
//         adj[u].push_back({ v, { { 0, 0 }, { 0, 0 } } });
//         adj[v].push_back({ u, { { 0, 0 }, { 0, 0 } } });
//     }
//     // dbg(0);
//     set<pair<ll, ll>> st;
//     for (int i = 1; i <= n; i++) {
//         auto it = dfs(adj, i, 0);
//         dbg(max(it.xx.xx, it.yy.xx));
//         st.insert({ max(it.xx.xx, it.yy.xx), i });
//     }
//     cout << st.begin()->first << " " << st.begin()->second << "\n";
// }

// int32_t main()
// {
//     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//     int t = 1;
//     // cin >> t;
//     for (int i = 1; i <= t; i++) {
//         // cout << "Case #" << i << ": "; // cout << "Case " << i << ": ";
//         Solve();
//     }
//     return 0;
// }
// // Coded by Tahsin Arafat (@TahsinArafat)
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;
#define sz(x) (ll)(x).size()
#define rd ({ll x; cin >> x; x; })
#define dbg(x) cerr << "[" #x "]  " << (x) << "\n\n"
// #define errv(x) {cerr << "["#x"]  ["; for (const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
// #define errvn(x, n) {cerr << "["#x"]  ["; for (auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define cerr \
    if (0)   \
    cerr
#define xx first
#define yy second
mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
/*_________________________________________________________________________________________________________________________*/
vector<ll> out;
struct cNode {
    ll u, len;
};
ll dfs(vector<cNode> adj[], ll node, ll par)
{
    cerr << node << "<---" << par << "\n";
    // cerr << node << endl;
    // if (out[node] != -1)
    //     return out[node];
    ll newLen = 0;
    for (cNode& it : adj[node]) {
        if (it.u == par)
            continue;
        if (it.len == -1)
            it.len = dfs(adj, it.u, node);
        newLen = max(newLen, it.len + 1);
    }
    return out[node] = newLen;
}
void Solve()
{
    ll n;
    cin >> n;
    out = vector<ll>(n + 1, -1);
    vector<cNode> adj[n + 1];
    for (int i = 0; i < n - 1; i++) {
        ll u, v;
        cin >> u >> v;
        adj[u].push_back({ v, -1 });
        adj[v].push_back({ u, -1 });
    }
    set<pair<ll, ll>> st;
    for (int i = 1; i <= n; i++) {
        st.insert({ dfs(adj, i, 0), i });
    }
    cout << st.begin()->first << " " << st.begin()->second << "\n";
}

int32_t main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": "; // cout << "Case " << i << ": ";
        Solve();
    }
    return 0;
}
// Coded by Tahsin Arafat (@TahsinArafat)

Information

Submit By
Type
Submission
Problem
P1069 Vaccination
Contest
Brain Booster #4
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-14 17:34:53
Judged At
2024-10-03 13:35:56
Judged By
Score
46
Total Time
103ms
Peak Memory
18.281 MiB