/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 103ms 14.746 MiB
#3 Accepted 108ms 14.738 MiB
#4 Accepted 104ms 14.703 MiB
#5 Accepted 101ms 14.738 MiB
#6 Accepted 103ms 14.738 MiB
#7 Wrong Answer 111ms 14.648 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-11-11 03:22:50
Judged By
Score
25
Total Time
111ms
Peak Memory
14.746 MiB