답안 #104734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104734 2019-04-09T03:29:46 Z Hideo Mergers (JOI19_mergers) C++14
0 / 100
96 ms 17696 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define vl vector < ll >
#define pi pair < int, int >
#define pii pair < int, pi >
#define vii vector < pi >

const int N = 5e5 + 7;
const int mod = 1e9 + 7;

int us[N], a[N], m[N], cur[N];
int n, k, ans;

vi g[N];

void dfs (int v = 1, int p = 0){
    for (int to : g[v]){
        if (to != p){
            dfs(to, v);
            cur[v] += cur[to];
        }
    }
    us[a[v]]++;
    if (us[a[v]] == 1)
        cur[v]--;
    if (us[a[v]] == m[a[v]]){
        cur[v]++;
        us[a[v]] = 0;
    }
    if (cur[v] == 0)
        ans++;
}

main(){
    cin >> n >> k;
    for (int i = 1; i < n; i++){
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].pb(b);
        g[b].pb(a);
    }
    for (int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        m[a[i]]++;
    }
    dfs();
    printf("%d", ans / 2);
}

Compilation message

mergers.cpp:41:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
mergers.cpp: In function 'int main()':
mergers.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~
mergers.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Incorrect 13 ms 12160 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Incorrect 13 ms 12160 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Incorrect 13 ms 12160 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 96 ms 17696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12032 KB Output is correct
2 Incorrect 13 ms 12160 KB Output isn't correct
3 Halted 0 ms 0 KB -