답안 #376745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
376745 2021-03-12T03:06:19 Z daniel920712 Mergers (JOI19_mergers) C++14
0 / 100
160 ms 54372 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];
vector < int > con[500005];
int sum[500005]={0};
int M;
void F(int here,int fa,int x)
{
    int i,j;
    //printf("aa %d %d\n",here,color[here]);
    con[here][color[here]]++;
    sum[color[here]]++;
    for(auto i:Next[here])
    {
        if(i==fa) continue;
        //printf("%d %d\n",here,i);
        F(i,here,x);
        for(j=1;j<=M;j++) con[here][j]+=con[i][j];
    }
    //printf("bb %d\n",here);
}
void F3(int here,int fa,int x)
{
    int ok=1,i,j;
    //con[here][color[here]]++;
    for(auto i:Next[here])
    {
        if(i==fa) continue;
        F3(i,here,x);
        for(j=1;j<=M;j++) if(con[here][j]>0&&con[here][j]<sum[j]) ok=0;
        if(ok) road.insert(make_pair(here,i));
    }
}
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 N,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]);
        for(j=0;j<=M;j++) con[i].push_back(0);
    }
    F(1,-1,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)':
mergers.cpp:19:9: warning: unused variable 'i' [-Wunused-variable]
   19 |     int i,j;
      |         ^
mergers.cpp: In function 'void F3(int, int, int)':
mergers.cpp:34:14: warning: unused variable 'i' [-Wunused-variable]
   34 |     int ok=1,i,j;
      |              ^
mergers.cpp: In function 'int main()':
mergers.cpp:61:24: warning: unused variable 'ok' [-Wunused-variable]
   61 |     int N,i,j,x,y,xx=0,ok=1;
      |                        ^~
mergers.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   62 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
mergers.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |         scanf("%d %d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~~
mergers.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   72 |         scanf("%d",&color[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 23936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 23936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 23936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 160 ms 54372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 23936 KB Output isn't correct
2 Halted 0 ms 0 KB -