답안 #376738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
376738 2021-03-12T02:54:23 Z daniel920712 Mergers (JOI19_mergers) C++14
34 / 100
3000 ms 15972 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];
void 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);
    }
}
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,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 main()':
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 Correct 8 ms 12012 KB Output is correct
2 Correct 10 ms 12140 KB Output is correct
3 Correct 10 ms 12140 KB Output is correct
4 Correct 10 ms 12012 KB Output is correct
5 Correct 8 ms 12012 KB Output is correct
6 Correct 8 ms 12140 KB Output is correct
7 Correct 8 ms 12012 KB Output is correct
8 Correct 9 ms 12140 KB Output is correct
9 Correct 9 ms 12012 KB Output is correct
10 Correct 10 ms 12012 KB Output is correct
11 Correct 9 ms 12140 KB Output is correct
12 Correct 9 ms 12140 KB Output is correct
13 Correct 8 ms 12012 KB Output is correct
14 Correct 10 ms 12140 KB Output is correct
15 Correct 9 ms 12140 KB Output is correct
16 Correct 9 ms 12012 KB Output is correct
17 Correct 9 ms 12012 KB Output is correct
18 Correct 9 ms 12140 KB Output is correct
19 Correct 8 ms 12012 KB Output is correct
20 Correct 9 ms 12012 KB Output is correct
21 Correct 9 ms 12140 KB Output is correct
22 Correct 9 ms 12140 KB Output is correct
23 Correct 9 ms 12012 KB Output is correct
24 Correct 8 ms 12012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12012 KB Output is correct
2 Correct 10 ms 12140 KB Output is correct
3 Correct 10 ms 12140 KB Output is correct
4 Correct 10 ms 12012 KB Output is correct
5 Correct 8 ms 12012 KB Output is correct
6 Correct 8 ms 12140 KB Output is correct
7 Correct 8 ms 12012 KB Output is correct
8 Correct 9 ms 12140 KB Output is correct
9 Correct 9 ms 12012 KB Output is correct
10 Correct 10 ms 12012 KB Output is correct
11 Correct 9 ms 12140 KB Output is correct
12 Correct 9 ms 12140 KB Output is correct
13 Correct 8 ms 12012 KB Output is correct
14 Correct 10 ms 12140 KB Output is correct
15 Correct 9 ms 12140 KB Output is correct
16 Correct 9 ms 12012 KB Output is correct
17 Correct 9 ms 12012 KB Output is correct
18 Correct 9 ms 12140 KB Output is correct
19 Correct 8 ms 12012 KB Output is correct
20 Correct 9 ms 12012 KB Output is correct
21 Correct 9 ms 12140 KB Output is correct
22 Correct 9 ms 12140 KB Output is correct
23 Correct 9 ms 12012 KB Output is correct
24 Correct 8 ms 12012 KB Output is correct
25 Correct 9 ms 12140 KB Output is correct
26 Correct 1602 ms 12780 KB Output is correct
27 Correct 309 ms 12140 KB Output is correct
28 Correct 2142 ms 12872 KB Output is correct
29 Correct 1906 ms 12800 KB Output is correct
30 Correct 852 ms 12268 KB Output is correct
31 Correct 9 ms 12140 KB Output is correct
32 Correct 2315 ms 12596 KB Output is correct
33 Correct 9 ms 12140 KB Output is correct
34 Correct 430 ms 12268 KB Output is correct
35 Correct 1882 ms 12652 KB Output is correct
36 Correct 345 ms 12140 KB Output is correct
37 Correct 1439 ms 12568 KB Output is correct
38 Correct 10 ms 12288 KB Output is correct
39 Correct 1488 ms 12452 KB Output is correct
40 Correct 224 ms 12268 KB Output is correct
41 Correct 291 ms 12396 KB Output is correct
42 Correct 1230 ms 12396 KB Output is correct
43 Correct 249 ms 12396 KB Output is correct
44 Correct 10 ms 12140 KB Output is correct
45 Correct 2105 ms 12780 KB Output is correct
46 Correct 1366 ms 12528 KB Output is correct
47 Correct 9 ms 12140 KB Output is correct
48 Correct 893 ms 12524 KB Output is correct
49 Correct 1597 ms 12732 KB Output is correct
50 Correct 2106 ms 12832 KB Output is correct
51 Correct 940 ms 12396 KB Output is correct
52 Correct 433 ms 12268 KB Output is correct
53 Correct 1222 ms 12652 KB Output is correct
54 Correct 669 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12012 KB Output is correct
2 Correct 10 ms 12140 KB Output is correct
3 Correct 10 ms 12140 KB Output is correct
4 Correct 10 ms 12012 KB Output is correct
5 Correct 8 ms 12012 KB Output is correct
6 Correct 8 ms 12140 KB Output is correct
7 Correct 8 ms 12012 KB Output is correct
8 Correct 9 ms 12140 KB Output is correct
9 Correct 9 ms 12012 KB Output is correct
10 Correct 10 ms 12012 KB Output is correct
11 Correct 9 ms 12140 KB Output is correct
12 Correct 9 ms 12140 KB Output is correct
13 Correct 8 ms 12012 KB Output is correct
14 Correct 10 ms 12140 KB Output is correct
15 Correct 9 ms 12140 KB Output is correct
16 Correct 9 ms 12012 KB Output is correct
17 Correct 9 ms 12012 KB Output is correct
18 Correct 9 ms 12140 KB Output is correct
19 Correct 8 ms 12012 KB Output is correct
20 Correct 9 ms 12012 KB Output is correct
21 Correct 9 ms 12140 KB Output is correct
22 Correct 9 ms 12140 KB Output is correct
23 Correct 9 ms 12012 KB Output is correct
24 Correct 8 ms 12012 KB Output is correct
25 Correct 9 ms 12140 KB Output is correct
26 Execution timed out 3065 ms 15972 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3048 ms 15972 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12012 KB Output is correct
2 Correct 10 ms 12140 KB Output is correct
3 Correct 10 ms 12140 KB Output is correct
4 Correct 10 ms 12012 KB Output is correct
5 Correct 8 ms 12012 KB Output is correct
6 Correct 8 ms 12140 KB Output is correct
7 Correct 8 ms 12012 KB Output is correct
8 Correct 9 ms 12140 KB Output is correct
9 Correct 9 ms 12012 KB Output is correct
10 Correct 10 ms 12012 KB Output is correct
11 Correct 9 ms 12140 KB Output is correct
12 Correct 9 ms 12140 KB Output is correct
13 Correct 8 ms 12012 KB Output is correct
14 Correct 10 ms 12140 KB Output is correct
15 Correct 9 ms 12140 KB Output is correct
16 Correct 9 ms 12012 KB Output is correct
17 Correct 9 ms 12012 KB Output is correct
18 Correct 9 ms 12140 KB Output is correct
19 Correct 8 ms 12012 KB Output is correct
20 Correct 9 ms 12012 KB Output is correct
21 Correct 9 ms 12140 KB Output is correct
22 Correct 9 ms 12140 KB Output is correct
23 Correct 9 ms 12012 KB Output is correct
24 Correct 8 ms 12012 KB Output is correct
25 Correct 9 ms 12140 KB Output is correct
26 Correct 1602 ms 12780 KB Output is correct
27 Correct 309 ms 12140 KB Output is correct
28 Correct 2142 ms 12872 KB Output is correct
29 Correct 1906 ms 12800 KB Output is correct
30 Correct 852 ms 12268 KB Output is correct
31 Correct 9 ms 12140 KB Output is correct
32 Correct 2315 ms 12596 KB Output is correct
33 Correct 9 ms 12140 KB Output is correct
34 Correct 430 ms 12268 KB Output is correct
35 Correct 1882 ms 12652 KB Output is correct
36 Correct 345 ms 12140 KB Output is correct
37 Correct 1439 ms 12568 KB Output is correct
38 Correct 10 ms 12288 KB Output is correct
39 Correct 1488 ms 12452 KB Output is correct
40 Correct 224 ms 12268 KB Output is correct
41 Correct 291 ms 12396 KB Output is correct
42 Correct 1230 ms 12396 KB Output is correct
43 Correct 249 ms 12396 KB Output is correct
44 Correct 10 ms 12140 KB Output is correct
45 Correct 2105 ms 12780 KB Output is correct
46 Correct 1366 ms 12528 KB Output is correct
47 Correct 9 ms 12140 KB Output is correct
48 Correct 893 ms 12524 KB Output is correct
49 Correct 1597 ms 12732 KB Output is correct
50 Correct 2106 ms 12832 KB Output is correct
51 Correct 940 ms 12396 KB Output is correct
52 Correct 433 ms 12268 KB Output is correct
53 Correct 1222 ms 12652 KB Output is correct
54 Correct 669 ms 12268 KB Output is correct
55 Correct 9 ms 12140 KB Output is correct
56 Execution timed out 3065 ms 15972 KB Time limit exceeded
57 Halted 0 ms 0 KB -