Submission #79421

# Submission time Handle Problem Language Result Execution time Memory
79421 2018-10-13T17:16:07 Z duality Mousetrap (CEOI17_mousetrap) C++11
25 / 100
1488 ms 68536 KB
#define DEBUG 1

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int t,m;
vi adjList[1000001];
int parent[1000001];
int dp[1000001],dp2[1000001];
int doDFS(int u,int p) {
    int i;
    int m1 = 0,m2 = 0,c = 0;
    parent[u] = p;
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        if (v != p) {
            doDFS(v,u);
            if (dp[v] >= m1) m2 = m1,m1 = dp[v];
            else if (dp[v] >= m2) m2 = dp[v];
            c++;
        }
    }
    dp[u] = m2+c;
    return dp[u];
}
vi path;
int doDFS2(int u,int p) {
    int i;
    if (u != t) {
        int s = 0;
        for (i = 1; i < path.size(); i++) s += adjList[path[i]].size()-2;
        if (p == t) dp2[u] = 0;
        else {
            int a = -1,b = -1;
            for (i = 0; i < adjList[p].size(); i++) {
                int v = adjList[p][i];
                if ((v != parent[p]) && (v != u)) {
                    if (dp[v] >= a) b = a,a = dp[v];
                    else if (dp[v] >= b) b = dp[v];
                }
            }
            int m1 = max(dp2[p],a+s);
            int m2 = max(dp2[p]+1,b+s);
            dp2[u] = min(m1,m2);
        }
    }
    path.pb(u);
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        if (v != p) doDFS2(v,u);
    }
    path.pop_back();
    return 0;
}
int main() {
    int i;
    int n;
    int a,b;
    scanf("%d %d %d",&n,&t,&m),t--,m--;
    for (i = 1; i < n; i++) {
        scanf("%d %d",&a,&b);
        a--,b--;
        adjList[a].pb(b);
        adjList[b].pb(a);
    }
    adjList[m].pb(n);
    adjList[n].pb(m);
    doDFS(t,-1);
    doDFS2(t,-1);
    //printArr(dp,n+1);
    //printArr(dp2,n+1);
    printf("%d\n",dp2[n]);

    return 0;
}

Compilation message

mousetrap.cpp: In function 'int doDFS(int, int)':
mousetrap.cpp:66:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
mousetrap.cpp: In function 'int doDFS2(int, int)':
mousetrap.cpp:83:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 1; i < path.size(); i++) s += adjList[path[i]].size()-2;
                     ~~^~~~~~~~~~~~~
mousetrap.cpp:87:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (i = 0; i < adjList[p].size(); i++) {
                         ~~^~~~~~~~~~~~~~~~~~~
mousetrap.cpp:100:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
mousetrap.cpp: In function 'int main()':
mousetrap.cpp:111:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&n,&t,&m),t--,m--;
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
mousetrap.cpp:113:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23980 KB Output is correct
3 Correct 23 ms 23980 KB Output is correct
4 Correct 23 ms 24020 KB Output is correct
5 Incorrect 23 ms 24096 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 512 ms 67192 KB Output is correct
2 Correct 503 ms 67192 KB Output is correct
3 Correct 1488 ms 68332 KB Output is correct
4 Correct 665 ms 68332 KB Output is correct
5 Correct 1387 ms 68332 KB Output is correct
6 Correct 1373 ms 68536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23980 KB Output is correct
3 Correct 23 ms 23980 KB Output is correct
4 Correct 23 ms 24020 KB Output is correct
5 Incorrect 23 ms 24096 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23980 KB Output is correct
3 Correct 23 ms 23980 KB Output is correct
4 Correct 23 ms 24020 KB Output is correct
5 Incorrect 23 ms 24096 KB Output isn't correct
6 Halted 0 ms 0 KB -