답안 #1110945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110945 2024-11-11T03:55:11 Z qrupafjzvm1 Mousetrap (CEOI17_mousetrap) C++14
0 / 100
51 ms 25160 KB
//memset 0x3f -> > 1000000000
#include <bits/stdc++.h>
#define f first
#define s second
#define MAXSIZE (int)(2e5+5)
#define MAXINT (int)(1e9)
#define MAXLL (int)(1e18)
#define log2int(x) (32 - __builtin_clz(x) - 1)
#define log2ll(x) (64ll - __builtin_clzll(x) - 1ll)
#define LSOne(x) (x & (-x))
// #define int long long
// #define MAXINT MAXLL
// #define log2int log2ll
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
typedef pair<int,int> ii;
string answerString[2] = {"NO", "YES"};
int add(int x, int y, int mod)
{
    int t = x + y;
    return t - mod * (t>=mod);
}
int sub(int x, int y, int mod)
{
    int t = x - y;
    return t + mod * (t<0);
}
//notes
int n, t, m;
vector <int> g[MAXSIZE];
bool flagged = false;
int dfs(int u, int p)
{
    if (u == t)
    {
        flagged = true;
        return 0;
    }

    priority_queue <int> pq;
    bool paOfT = false; int valOfT = 0;
    for (int v : g[u])
    if (v != p)
    {
        int val = dfs(v, u);
        if (flagged)
        {
            paOfT = true;
            valOfT = val;
        }
        else pq.push(val + 1);
    }

    int sum = 0;
    while (!pq.empty())
    {
        sum++; pq.pop();
        if (pq.empty()) break;
        sum += pq.top(); pq.pop();
    }
    if (paOfT)
    {
        flagged = true;
        sum += valOfT;
    }
    else flagged = false;
    //cout<<u<<" "<<sum<<endl;
    return sum;
}
signed main()
{
    //freopen("text.inp","r",stdin);
    //freopen("text.out","w",stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>t>>m;
    for (int i=1;i<n;i++)
    {
        int u, v; cin>>u>>v;
        g[u].push_back(v); g[v].push_back(u);
    }
    cout<<dfs(m, -1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Incorrect 2 ms 4996 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 51 ms 25160 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Incorrect 2 ms 4996 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Incorrect 2 ms 4996 KB Output isn't correct
6 Halted 0 ms 0 KB -