Submission #577728

# Submission time Handle Problem Language Result Execution time Memory
577728 2022-06-15T08:26:07 Z amunduzbaev Star Trek (CEOI20_startrek) C++17
0 / 100
3 ms 3028 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
vector<int> edges[N];
int dp[N], sub[N], up[N];
int is[N][2], cnt[N];
ar<int, 2> C{};

void dfs(int u, int p = -1){
	cnt[u] = 1;
	for(auto x : edges[u]){
		if(x == p) continue;
		dfs(x, u);
		if(dp[x] == 0) dp[u] = 1;
		cnt[u] += cnt[x];
	}
	sub[u] = dp[u];
}

void re(int u, int p = -1){
	if(up[u] == 0) dp[u] = 1;
	ar<int, 2> c {};
	c[up[u]]++;
	for(auto x : edges[u]){
		if(x == p) continue;
		c[dp[x]]++;
	}
	
	for(auto x : edges[u]){
		if(x == p) continue;
		c[dp[x]]--;
		if(c[0]) up[x] = 1;
		re(x, u);
	}
}

int n;
void dfs2(int u, int p = -1){
	int f = 0, v = -1;
	for(auto x : edges[u]){
		if(x == p) continue;
		dfs2(x, u);
		if(!sub[x]){
			f++, v = x;
		}
	}
	
	if(f > 1){
		is[u][1] = cnt[u] * 1ll * n % mod;
	} else if(f == 1) {
		is[u][1] = (cnt[u] - cnt[v]) * 1ll * n % mod;
		is[u][1] = (is[u][1] + is[v][0]), is[u][0] = (is[u][0] + is[v][1]);
	} else {
		is[u][1] = C[0], is[u][0] = C[1];
		for(auto x : edges[u]){
			if(x == p) continue;
			is[u][0] = (is[u][0] + is[x][1]), is[u][1] = (is[u][1] + is[x][0]);
		}
	}
}

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int d; cin>>n>>d;
	for(int i=1;i<n;i++){
		int a, b; cin>>a>>b;
		edges[a].push_back(b);
		edges[b].push_back(a);
		edges[a + n].push_back(b + n);
		edges[b + n].push_back(a + n);
	}
	
	int res = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			edges[i].push_back(j + n);
			memset(dp, 0, sizeof dp);
			dfs(i);
			if(dp[i]) res++;
			edges[i].pop_back();
		}
	}
	
	cout<<res<<"\n";
}

/*

4 1
1 2
2 3
2 4

*/

# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -