Submission #359886

# Submission time Handle Problem Language Result Execution time Memory
359886 2021-01-27T09:32:52 Z daniel920712 Cats or Dogs (JOI18_catdog) C++14
38 / 100
3000 ms 7768 KB
#include "catdog.h"
#include <vector>

using namespace std;

int x,now=1;
bool have1[1000005];
bool have2[1000005];
int vis[5][1000005];
int DP[5][1000005];
vector < int > Next[100005];
int color[1000005];
int N;
void initialize(int N, std::vector<int> A, std::vector<int> B)
{
    int i;
    ::N=N;
    for(i=0;i<N-1;i++)
    {
        Next[A[i]].push_back(B[i]);
        Next[B[i]].push_back(A[i]);
    }
}
int F(int color,int here,int fa)
{
    if(::color[here]!=color&&::color[here]) return 1e9;
    if(vis[color][here]==now) return DP[color][here];
    vis[color][here]=now;
    DP[color][here]=0;
    for(auto i:Next[here])
    {
        if(i==fa) continue;
        DP[color][here]+=min(F(color,i,here),F(3-color,i,here)+1);
    }
    return DP[color][here];

}
int cat(int v)
{
    now++;
    color[v]=1;
    return min(F(1,1,-1),F(2,1,-1));
}

int dog(int v)
{
    now++;
    color[v]=2;
    return min(F(1,1,-1),F(2,1,-1));
}

int neighbor(int v)
{
    now++;
    color[v]=0;
    return min(F(1,1,-1),F(2,1,-1));
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 26 ms 2796 KB Output is correct
18 Correct 35 ms 2796 KB Output is correct
19 Correct 17 ms 2796 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 6 ms 2924 KB Output is correct
22 Correct 7 ms 2796 KB Output is correct
23 Correct 37 ms 2796 KB Output is correct
24 Correct 30 ms 2944 KB Output is correct
25 Correct 13 ms 2796 KB Output is correct
26 Correct 8 ms 2796 KB Output is correct
27 Correct 6 ms 2796 KB Output is correct
28 Correct 9 ms 2796 KB Output is correct
29 Correct 37 ms 2924 KB Output is correct
30 Correct 6 ms 2668 KB Output is correct
31 Correct 5 ms 2796 KB Output is correct
32 Correct 10 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 26 ms 2796 KB Output is correct
18 Correct 35 ms 2796 KB Output is correct
19 Correct 17 ms 2796 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 6 ms 2924 KB Output is correct
22 Correct 7 ms 2796 KB Output is correct
23 Correct 37 ms 2796 KB Output is correct
24 Correct 30 ms 2944 KB Output is correct
25 Correct 13 ms 2796 KB Output is correct
26 Correct 8 ms 2796 KB Output is correct
27 Correct 6 ms 2796 KB Output is correct
28 Correct 9 ms 2796 KB Output is correct
29 Correct 37 ms 2924 KB Output is correct
30 Correct 6 ms 2668 KB Output is correct
31 Correct 5 ms 2796 KB Output is correct
32 Correct 10 ms 2796 KB Output is correct
33 Execution timed out 3072 ms 7768 KB Time limit exceeded
34 Halted 0 ms 0 KB -