/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Wrong Answer 4ms 324.0 KiB
#2 Time Exceeded ≥2067ms ≥6.273 MiB
#3 Time Exceeded ≥2083ms ≥6.336 MiB
#4 Time Exceeded ≥2092ms ≥6.387 MiB
#5 Time Exceeded ≥2074ms ≥6.383 MiB
#6 Time Exceeded ≥2084ms ≥6.152 MiB
#7 Time Exceeded ≥2064ms ≥6.215 MiB
#8 Time Exceeded ≥2083ms ≥6.281 MiB
#9 Time Exceeded ≥2081ms ≥6.387 MiB
#10 Time Exceeded ≥2093ms ≥6.379 MiB
#11 Time Exceeded ≥2082ms ≥6.234 MiB
#12 Time Exceeded ≥2072ms ≥6.375 MiB
#13 Time Exceeded ≥2056ms ≥6.391 MiB
#14 Time Exceeded ≥2085ms ≥6.391 MiB
#15 Time Exceeded ≥2076ms ≥6.383 MiB
#16 Time Exceeded ≥2065ms ≥6.387 MiB
#17 Time Exceeded ≥2080ms ≥6.383 MiB
#18 Time Exceeded ≥2091ms ≥6.387 MiB
#19 Time Exceeded ≥2091ms ≥6.176 MiB
#20 Time Exceeded ≥2091ms ≥6.391 MiB
#21 Wrong Answer 3ms 532.0 KiB
#22 Wrong Answer 3ms 324.0 KiB
#23 Wrong Answer 41ms 12.164 MiB
#24 Wrong Answer 41ms 12.203 MiB
#25 Wrong Answer 3ms 324.0 KiB
#26 Wrong Answer 18ms 1.82 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;
const int MX = 1e5 + 5 ;
vector<int> Edge[MX] ;
int cnt = 0 , days = 0 , n , u , v , farthestNode = 0 , lev[MX] , mnDays;
vector < int > Ans ;
vector<bool> removed;
void dfs(int id , int par){
  for(auto child : Edge[id]){
    if(child != par){
        lev[child] = lev[id] + 1 ;
        if(days < lev[child]){
            days = lev[child] ;
            farthestNode = child ;
        }
        dfs(child , id) ;
    }
  }
}

void solve()
{
    cin >> n ;
    for(int i = 1 ; i < n ; i++){
        cin >> u >> v ;
        Edge[u].pb(v) ;
        Edge[v].pb(u) ;

    }
    dfs(1 , -1) ;
    for(int i = 1 ; i <= n ; i++) lev[i] = 0;
    cout << farthestNode << endl ;
    dfs(farthestNode , -1) ;
    mnDays = (days + 1) >> 1 ;
    vector < int > node ;
    for(int i = 1 ; i <= n; i++){
        if(lev[i] == mnDays || lev[i] == mnDays + 1){
            node.pb(i) ;
        }
    }
    for(int i = node.size() - 1 ; i >= 0 ; i--){
        fill(lev , lev + n , 0) ;
        days = 0 ;
        dfs(node[i] , -1) ;
        if(days == mnDays){
            cout << mnDays << " " << node[i] << endl ;
            break ;
        }
    }

}
int main()
{
     __Heart__
     int t ; t = 1 ; while(t--) solve() ;
}

Information

Submit By
Type
Submission
Problem
P1069 Vaccination
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-12 01:47:26
Judged At
2024-10-03 13:40:55
Judged By
Score
0
Total Time
≥2093ms
Peak Memory
≥12.203 MiB