Submission #855793

# Submission time Handle Problem Language Result Execution time Memory
855793 2023-10-01T19:47:15 Z mychecksedad Mousetrap (CEOI17_mousetrap) C++17
25 / 100
630 ms 73308 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 22;

int n, s, t, dp[N];
vector<int> g[N];
void dfs(int v, int p){
  dp[v] = 0;
  vector<int> dps;
  for(int u: g[v]){
    if(u != p && u != t){
      dfs(u, v);
      dps.pb(dp[u]);
    }
  }
  sort(all(dps), greater<int>());
  dp[v] = dps.size() <= 1 ? int(dps.size()) : dps[1] + (dps.size() - 1) + 1;
}

void solve(){
  cin >> n >> t >> s;
  for(int i = 0; i < n - 1; ++i){
    int u, v; cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(s, 0);
  cout << dp[s];
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

mousetrap.cpp: In function 'int main()':
mousetrap.cpp:41:15: warning: unused variable 'aa' [-Wunused-variable]
   41 |   int tt = 1, aa;
      |               ^~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 25180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 221 ms 59100 KB Output is correct
2 Correct 238 ms 55548 KB Output is correct
3 Correct 574 ms 60240 KB Output is correct
4 Correct 237 ms 49772 KB Output is correct
5 Correct 589 ms 73308 KB Output is correct
6 Correct 630 ms 73292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 25180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 25180 KB Output isn't correct
2 Halted 0 ms 0 KB -