Submission #376832

# Submission time Handle Problem Language Result Execution time Memory
376832 2021-03-12T05:11:16 Z daniel920712 Mergers (JOI19_mergers) C++14
0 / 100
256 ms 55908 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <set>
#include <vector>

using namespace std;
set < int > a,b;
set < pair < int , int > > road;
int now=0;
vector < int > Next[500005];
int color[500005];
int deg[500005]={0};
vector < int > con[500005];
int sum[500005]={0};
int d[500005];
int Father[500005];
int N,M;
void F(int here,int fa,int x,int deg)
{
    int i,j;
    Father[here]=fa;
    if(M<=50||N<=3000)
    {
        con[here][color[here]]++;
        sum[color[here]]++;
    }
    for(auto i:Next[here])
    {
        if(i==fa) continue;
        F(i,here,x,deg+1);
        d[here]=deg;
        if(M<=50||N<=3000)
        {
            con[here][color[here]]++;
            sum[color[here]]++;
        }
    }
}
void F3(int here,int fa,int x)
{
    int ok=1,i,j;
    for(auto i:Next[here])
    {
        ok=1;
        if(i==fa) continue;
        F3(i,here,x);
        if(M<=50||N<=3000)
        {
            con[here][color[here]]++;
            sum[color[here]]++;
            for(j=1;j<=M;j++)
            {
                if(con[i][j]>0&&con[i][j]<sum[j])
                {
                    ok=0;
                }
            }
        }

        if(ok)
        {
            //printf("%d %d\n",here,i);
            road.insert(make_pair(here,i));
            road.insert(make_pair(i,here));
        }
    }
}
void F2(int here,int fa,int xx)
{
    for(auto i:Next[here])
    {
        if(i==fa) continue;
        if(road.find(make_pair(here,i))!=road.end())
        {
            now++;
            deg[xx]++;
            deg[now]++;
            F2(i,here,now);
        }
        else F2(i,here,xx);
    }
}
int main()
{
    int i,j,x,y,xx=0,ok=1;
    scanf("%d %d",&N,&M);
    for(i=1;i<N;i++)
    {
        scanf("%d %d",&x,&y);
        Next[x].push_back(y);
        Next[y].push_back(x);

    }
    for(i=1;i<=N;i++)
    {
        scanf("%d",&color[i]);
        if(M<=50||N<=3000) for(j=0;j<=M;j++) con[i].push_back(0);
    }
    F(1,-1,0,0);
    F3(1,-1,0);
    now=0;
    F2(1,-1,0);
    for(i=0;i<=now;i++) if(deg[i]==1) xx++;

    if(xx==1) printf("0\n");
    else printf("%d\n",(xx+1)/2);
    return 0;
}

Compilation message

mergers.cpp: In function 'void F(int, int, int, int)':
mergers.cpp:21:9: warning: unused variable 'i' [-Wunused-variable]
   21 |     int i,j;
      |         ^
mergers.cpp:21:11: warning: unused variable 'j' [-Wunused-variable]
   21 |     int i,j;
      |           ^
mergers.cpp: In function 'void F3(int, int, int)':
mergers.cpp:42:14: warning: unused variable 'i' [-Wunused-variable]
   42 |     int ok=1,i,j;
      |              ^
mergers.cpp: In function 'int main()':
mergers.cpp:86:22: warning: unused variable 'ok' [-Wunused-variable]
   86 |     int i,j,x,y,xx=0,ok=1;
      |                      ^~
mergers.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   87 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
mergers.cpp:90:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   90 |         scanf("%d %d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~~
mergers.cpp:97:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   97 |         scanf("%d",&color[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 169 ms 55908 KB Output is correct
2 Correct 256 ms 39444 KB Output is correct
3 Incorrect 61 ms 48236 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23788 KB Output isn't correct
2 Halted 0 ms 0 KB -