Submission #468719

# Submission time Handle Problem Language Result Execution time Memory
468719 2021-08-29T13:28:47 Z Redmoonautumn Mousetrap (CEOI17_mousetrap) C++17
0 / 100
845 ms 63040 KB
#include <bits/stdc++.h>
using namespace std;

#define int int64_t

vector<vector<int>> graph;
vector<int> mousepath;
vector<bool> inmousepath;

bool dfs1(int v,  int t, int p=-1){
    if(v==t)return true;
    for(auto u:graph[v]){
        if(u==p)continue;
        if(dfs1(u,t,v)){
            //cout<<"hi\n";
            mousepath.push_back(v);
            inmousepath[v]=true;
            return true;
        }
    }
    return false;
}

int dfs2(int v, int p=-1){
    //if(inmousepath[v]&&p!=-1)return 0;
    priority_queue<int> pq;
    for(auto u:graph[v]){
        if(u==p||inmousepath[u])continue;
        int x=dfs2(u,v);
        pq.push(x);
    }
    int sum=0;
    int i=0;
    while (!pq.empty()){
        sum++;
        if(i%2)sum+=pq.top();
        i++;
        pq.pop();
    }
    return sum;
}

void pv(vector<int> & v){
    for(auto u:v){
        cout<<u<<" ";
    }
    cout<<endl;
}
void pv(vector<bool> & v){
    for(auto u:v){
        cout<<u<<" ";
    }
    cout<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n,t,m;
    cin>>n>>t>>m;
    graph.resize(n);
    t--;
    m--;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    inmousepath.resize(n);
    inmousepath[t]=true;
    dfs1(m,t);
    //cout<<<<endl;
    //pv(mousepath);
    //pv(inmousepath);
    int sol=0;
    for(auto u:mousepath){
        int aha=dfs2(u);
        sol+= aha;
        //cout<<aha<<" ";
    }
    //cout<<endl;
    cout<<sol<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 392 ms 63040 KB Output is correct
2 Correct 344 ms 56856 KB Output is correct
3 Incorrect 845 ms 61292 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -