Submission #1110946

# Submission time Handle Problem Language Result Execution time Memory
1110946 2024-11-11T03:55:50 Z qrupafjzvm1 Mousetrap (CEOI17_mousetrap) C++14
0 / 100
649 ms 74432 KB
//memset 0x3f -> > 1000000000
#include <bits/stdc++.h>
#define f first
#define s second
#define MAXSIZE (int)(1e6+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);
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23888 KB Output is correct
2 Correct 5 ms 23888 KB Output is correct
3 Correct 5 ms 23888 KB Output is correct
4 Correct 5 ms 23888 KB Output is correct
5 Incorrect 5 ms 23888 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 223 ms 73412 KB Output is correct
2 Correct 203 ms 65100 KB Output is correct
3 Incorrect 649 ms 74432 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23888 KB Output is correct
2 Correct 5 ms 23888 KB Output is correct
3 Correct 5 ms 23888 KB Output is correct
4 Correct 5 ms 23888 KB Output is correct
5 Incorrect 5 ms 23888 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23888 KB Output is correct
2 Correct 5 ms 23888 KB Output is correct
3 Correct 5 ms 23888 KB Output is correct
4 Correct 5 ms 23888 KB Output is correct
5 Incorrect 5 ms 23888 KB Output isn't correct
6 Halted 0 ms 0 KB -