답안 #376733

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
376733 2021-03-12T02:52:18 Z daniel920712 Mergers (JOI19_mergers) C++14
0 / 100
69 ms 32228 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];
int F(int here,int fa,int x)
{
    if(x==0) a.insert(color[here]);
    else b.insert(color[here]);
    for(auto i:Next[here])
    {
        if(i==fa) continue;
        F(i,here,x);
    }
}
int 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,M,i,x,y,con=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(i=1;i<=N;i++)
    {
        for(auto j:Next[i])
        {
            if(i<j)
            {
                ok=1;
                a.clear();
                b.clear();
                F(i,j,0);
                F(j,i,1);
                for(auto k:a) if(b.find(k)!=b.end()) ok=0;
                for(auto k:b) if(a.find(k)!=a.end()) ok=0;
                if(ok)
                {

                    road.insert(make_pair(i,j));
                    road.insert(make_pair(j,i));
                }
            }

        }
    }
    /*now=0;
    F2(1,-1,0);
    for(i=0;i<=now;i++)
    {
        if(deg[i]==1) con++;
    }
    if(con==1) printf("0\n");
    else printf("%d\n",(con+1)/2);*/
    return 0;
}

Compilation message

mergers.cpp: In function 'int F(int, int, int)':
mergers.cpp:23:1: warning: no return statement in function returning non-void [-Wreturn-type]
   23 | }
      | ^
mergers.cpp: In function 'int F2(int, int, int)':
mergers.cpp:38:1: warning: no return statement in function returning non-void [-Wreturn-type]
   38 | }
      | ^
mergers.cpp: In function 'int main()':
mergers.cpp:41:19: warning: unused variable 'con' [-Wunused-variable]
   41 |     int N,M,i,x,y,con=0,ok=1;
      |                   ^~~
mergers.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
mergers.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |         scanf("%d %d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~~
mergers.cpp:49:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |     for(i=1;i<=N;i++) scanf("%d",&color[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 24300 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 24300 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 24300 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 69 ms 32228 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 24300 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -