Language: Java

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
int pow_mod(int a, int n, int mod) {
	if (n == 0)
		return 1;
	int ans = pow_mod(a, n / 2, mod);
	ans = ans * ans % mod;
	if (n % 2 == 1)
		ans = ans * a % mod;
	return ans;
}
//扩展GCD
int ex_gcd(int a, int b, int &x, int &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	int g = ex_gcd(b, a % b, x, y);
	int temp = x;
	x = y;
	y = temp - a / b * y;
	return g;
}
//扩展欧几里得的另一种写法
void ex_gcd(int a, int b, int &d, int &x, int &y) {
	//求解ax+by=gcd(a,b)的一组解
	if (!b) {
		d = a, x = 1, y = 0;
	} else {
		ex_gcd(b, a % b, d, y, x);
		y -= x * (a / b);
	}
}
//逆元
int inv(int a, int mod) {
	int X, Y;
	int g = ex_gcd(a, mod, X, Y);
	if (g != 1)
		return -1;
	return (X % mod + mod) % mod;
}
vector<int> G[maxn];
int sz[maxn];
int fa[maxn];
void dfs(int u, int f) {
	sz[u] = 1;
	fa[u] = f;
	for (int i = 0; i < G[u].size(); i++) {
		int v = G[u][i];
		if (v == f)
			continue;
		dfs(v, u);
		sz[u] += sz[v];
	}
}
int p[maxn];
signed main() {
	int n;
	scanf("%lld", &n);
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%lld%lld", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, -1);
	int ans = 0;
	int inv2 = inv(2, mod);
	for (int i = 1; i <= n; i++) {
		int tot = G[i].size();
		if (G[i].size() == 1)
			continue;
		int now = 1;
		for (int j = 0; j < tot; j++) {
			int v = G[i][j];
			int siz = 0;
			if (v == fa[i])
				siz = n - sz[i];
			else
				siz = sz[v];
			p[j] = (1 - inv(pow_mod(2, siz, mod), mod) + mod) % mod; //点黑的概率
			now *= ((1 - p[j] + mod) % mod);
			now %= mod;
		}
		int cur = now;
		for (int j = 0; j < tot; j++) {
			cur += now * inv((1 - p[j] + mod) % mod, mod) % mod * p[j] % mod;
			cur %= mod;
		}
		ans += inv2 * (1 - cur + mod) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;

}


Compiler output:
Main.java:1: error: illegal character: '#'
#include<bits/stdc++.h>
^
Main.java:1: error: class, interface, enum, or record expected
#include<bits/stdc++.h>
        ^
Main.java:2: error: illegal character: '#'
#define int long long
^
Main.java:4: error: class, interface, enum, or record expected
const int maxn = 2e5 + 10;
^
Main.java:5: error: class, interface, enum, or record expected
const int mod = 1e9 + 7;
^
Main.java:6: error: unnamed classes are a preview feature and are disabled by default.
int pow_mod(int a, int n, int mod) {
^
  (use --enable-preview to enable unnamed classes)
Main.java:16: error: <identifier> expected
int ex_gcd(int a, int b, int &x, int &y) {
                            ^
Main.java:16: error: class, interface, enum, or record expected
int ex_gcd(int a, int b, int &x, int &y) {
                                 ^
Main.java:19: error: class, interface, enum, or record expected
		y = 0;
		^
Main.java:20: error: class, interface, enum, or record expected
		return a;
		^
Main.java:21: error: class, interface, enum, or record expected
	}
	^
Main.java:24: error: class, interface, enum, or record expected
	x = y;
	^
Main.java:25: error: class, interface, enum, or record expected
	y = temp - a / b * y;
	^
Main.java:26: error: class, interface, enum, or record expected
	return g;
	^
Main.java:27: error: class, interface, enum, or record expected
}
^
Main.java:33: error: class, interface, enum, or record expected
	} else {
	^
Main.java:35: error: class, interface, enum, or record expected
		y -= x * (a / b);
		^
Main.java:36: error: class, interface, enum, or record expected
	}
	^
Main.java:42: error: class, interface, enum, or record expected
	if (g != 1)
	^
Main.java:44: error: class, interface, enum, or record expected
	return (X % mod + mod) % mod;
	^
Main.java:45: error: class, interface, enum, or record expected
}
^
Main.java:47: error: class, interface, enum, or record expected
int sz[maxn];
^
Main.java:48: error: class, interface, enum, or record expected
int fa[maxn];
^
Main.java:60: error: class, interface, enum, or record expected
int p[maxn];
^
Main.java:97: error: not a statement
	cout << ans << endl;
	            ^
Main.java:63: error: illegal start of expression
	scanf("%lld", &n);
	              ^
Main.java:66: error: illegal start of expression
		scanf("%lld%lld", &u, &v);
		                  ^
Main.java:66: error: illegal start of expression
		scanf("%lld%lld", &u, &v);
		                      ^
28 errors