Submission #105886

# Submission time Handle Problem Language Result Execution time Memory
105886 2019-04-15T14:21:20 Z Kepperoni Mergers (JOI19_mergers) C++14
0 / 100
93 ms 17664 KB
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

const int MAXN = 5e5 + 10;

int n, kk;
int gr[MAXN];
int le[MAXN], ri[MAXN];
int fi[MAXN], se[MAXN];
int cmi[MAXN], cma[MAXN], cnt[MAXN], tr[MAXN];
vector<int> k[MAXN];

int leaf = 1;
int ccnt = 1;
void prep(int v, int p = 0){
	le[v] = ccnt;
	ri[v] = ccnt;
	fi[gr[v]] = min(fi[gr[v]], ccnt);
	se[gr[v]] = max(se[gr[v]], ccnt);
	ccnt++;

	for(auto x : k[v]){
		if(x != p){
			prep(x, v);
			ri[v] = ri[x];
		}
	}
}

void go(int v, int p = 0){
	cmi[v] = fi[gr[v]];
	cma[v] = se[gr[v]];
	for(auto x : k[v]){
		if(x != p){
			go(x, v);				
			cmi[v] = min(cmi[v], cmi[x]);
			cma[v] = max(cma[v], cma[x]);
			cnt[v] += cnt[x];
		}
	}

	if(cmi[v] >= le[v] && cma[v] <= ri[v]){
		if(cnt[v] == 0)
			leaf++;
		if(cnt[v] == 1 && v == 1)
			leaf++;
		cnt[v] = 1;
	}
}

int main(){
	scanf(" %d %d", &n, &kk);
	
	for(int i=0; i<n-1; i++){
		int ca, cb; scanf(" %d %d", &ca, &cb);
		k[ca].pb(cb);
		k[cb].pb(ca);
	}

	for(int i=1; i<=n; i++) scanf(" %d", &gr[i]);
	for(int i=1; i<=kk; i++) fi[i] = 1e6;

	prep(1);
	go(1);

	printf("%d\n", leaf/2);
}

Compilation message

mergers.cpp: In function 'int main()':
mergers.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %d %d", &n, &kk);
  ~~~~~^~~~~~~~~~~~~~~~~~~
mergers.cpp:63:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int ca, cb; scanf(" %d %d", &ca, &cb);
               ~~~~~^~~~~~~~~~~~~~~~~~~~
mergers.cpp:68:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=n; i++) scanf(" %d", &gr[i]);
                          ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12160 KB Output is correct
2 Correct 18 ms 12160 KB Output is correct
3 Correct 14 ms 12080 KB Output is correct
4 Correct 13 ms 12160 KB Output is correct
5 Incorrect 14 ms 12160 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12160 KB Output is correct
2 Correct 18 ms 12160 KB Output is correct
3 Correct 14 ms 12080 KB Output is correct
4 Correct 13 ms 12160 KB Output is correct
5 Incorrect 14 ms 12160 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12160 KB Output is correct
2 Correct 18 ms 12160 KB Output is correct
3 Correct 14 ms 12080 KB Output is correct
4 Correct 13 ms 12160 KB Output is correct
5 Incorrect 14 ms 12160 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 17664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 12160 KB Output is correct
2 Correct 18 ms 12160 KB Output is correct
3 Correct 14 ms 12080 KB Output is correct
4 Correct 13 ms 12160 KB Output is correct
5 Incorrect 14 ms 12160 KB Output isn't correct
6 Halted 0 ms 0 KB -