# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
127058 | 2019-07-08T20:42:20 Z | Lawliet | Mousetrap (CEOI17_mousetrap) | C++14 | 1127 ms | 69532 KB |
#include <bits/stdc++.h> #define MAX 1000010 using namespace std; typedef long long int lli; int n; int mouse, trap; int n1, n2; int pai[MAX]; lli dp[MAX]; vector<int> grafo[MAX]; void DFS(int i, int p) { if(grafo[i].size() == 1 && i != trap) { dp[i] = 0; return; } vector<int> aux; aux.push_back( 0 ); for(int g = 0 ; g < grafo[i].size() ; g++) { int prox = grafo[i][g]; if(prox == p) continue; pai[prox] = i; //printf("i = %d prox = %d\n",i,prox); DFS(prox , i); aux.push_back( dp[prox] ); } sort(aux.begin() , aux.end()); dp[i] = grafo[i].size() - 2 + aux[aux.size() - 2] + 1; //printf("dp(%d) = %lld\n",i,dp[i]); } int main() { scanf("%d %d %d",&n,&trap,&mouse); for(int g = 0 ; g < n - 1 ; g++) { scanf("%d %d",&n1,&n2); grafo[n1].push_back(n2); grafo[n2].push_back(n1); } DFS(trap , trap); lli ans = dp[mouse]; int cur = mouse; while(cur != trap) { ans = max(ans , dp[cur]); cur = pai[cur]; } printf("%lld\n",ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23764 KB | Output is correct |
2 | Incorrect | 23 ms | 23928 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 520 ms | 68052 KB | Output is correct |
2 | Correct | 472 ms | 63980 KB | Output is correct |
3 | Correct | 1109 ms | 69420 KB | Output is correct |
4 | Correct | 531 ms | 47476 KB | Output is correct |
5 | Correct | 1127 ms | 69416 KB | Output is correct |
6 | Correct | 1107 ms | 69532 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23764 KB | Output is correct |
2 | Incorrect | 23 ms | 23928 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 23764 KB | Output is correct |
2 | Incorrect | 23 ms | 23928 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |