Submission #1117576

# Submission time Handle Problem Language Result Execution time Memory
1117576 2024-11-24T06:13:15 Z vjudge1 Unique Cities (JOI19_ho_t5) C++17
4 / 100
2000 ms 33040 KB
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define F first
#define S second
#define ull unsigned long long
#define db double
#define ldb long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ordered_set tree < ll, null_type, less < ll > , rb_tree_tag, tree_order_statistics_node_update >
#define all(x) x.begin(), x.end()

const int mod = 1e9 + 7;
const int N = 500001;

using namespace std;
using namespace __gnu_pbds;

ll n, m, a, b, c, p[N], ans, d[N], cnt[N], ls[N], num[N];
set <ll> s;
vector <ll> g[N];

ll binpow(ll a, ll b) {
    a %= mod;
    if (b == 0) {
        return 1;
    }
    else if (b % 2 == 1) {
        return binpow(a, b - 1) % mod * a % mod;
    }
    else {
        ll t = binpow(a, b / 2) % mod;
        return t * t % mod;
    }
}

void dfs (ll v, ll pr){
	for (int i = 0; i < g[v].size(); i++){
		if (g[v][i] != pr){
			d[g[v][i]] = d[v] + 1;
			if (cnt[d[g[v][i]]]){
				num[ls[d[g[v][i]]]]--;
				if (ls[d[g[v][i]]] != -1 && num[ls[d[g[v][i]]]] == 0)s.erase(ls[d[g[v][i]]]);
				ls[d[g[v][i]]] = -1;
//				cout << "del " << d[g[v][i]] << ' ' << g[v][i] << ' ' << p[g[v][i]] << ' ' << s.size() << '\n';
			}
			else{
				cnt[d[g[v][i]]]++;
				num[p[g[v][i]]]++;
				s.insert(p[g[v][i]]);
//				cout << "add " << d[g[v][i]] << ' ' << g[v][i] << ' ' << p[g[v][i]] << ' ' << s.size() << '\n';
				ls[d[g[v][i]]] = p[g[v][i]];
			}
			dfs (g[v][i], v);
		}
	}
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i < n; i++){
		cin >> a >> b;
		g[a].pb (b);
		g[b].pb (a);
	}
	for (int i = 1; i <= n; i++){
		cin >> p[i];
	}
	for (int i = 1; i <= n; i++){
		s.clear();
		d[i] = 1;
		dfs (i, i);
		for (int j = 1; j <= n; j++){
			cnt[j] = num[j] = 0;
		}
		cout << s.size() << '\n';
	}
}

Compilation message

joi2019_ho_t5.cpp: In function 'void dfs(long long int, long long int)':
joi2019_ho_t5.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for (int i = 0; i < g[v].size(); i++){
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19024 KB Output is correct
2 Correct 55 ms 19224 KB Output is correct
3 Correct 78 ms 19272 KB Output is correct
4 Correct 157 ms 19448 KB Output is correct
5 Correct 58 ms 19024 KB Output is correct
6 Correct 114 ms 19396 KB Output is correct
7 Correct 62 ms 19308 KB Output is correct
8 Correct 56 ms 19024 KB Output is correct
9 Correct 75 ms 19024 KB Output is correct
10 Correct 55 ms 19252 KB Output is correct
11 Correct 63 ms 19244 KB Output is correct
12 Correct 44 ms 19024 KB Output is correct
13 Correct 106 ms 19280 KB Output is correct
14 Correct 66 ms 19280 KB Output is correct
15 Correct 81 ms 19452 KB Output is correct
16 Correct 31 ms 19024 KB Output is correct
17 Correct 84 ms 19352 KB Output is correct
18 Correct 61 ms 19120 KB Output is correct
19 Correct 65 ms 19112 KB Output is correct
20 Correct 359 ms 19280 KB Output is correct
21 Correct 242 ms 19328 KB Output is correct
22 Correct 52 ms 19024 KB Output is correct
23 Correct 114 ms 19256 KB Output is correct
24 Correct 74 ms 19248 KB Output is correct
25 Correct 87 ms 19248 KB Output is correct
26 Correct 47 ms 19240 KB Output is correct
27 Correct 335 ms 19392 KB Output is correct
28 Correct 269 ms 19376 KB Output is correct
29 Correct 217 ms 19280 KB Output is correct
30 Correct 32 ms 19024 KB Output is correct
31 Correct 162 ms 19280 KB Output is correct
32 Correct 232 ms 19280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2058 ms 27720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2062 ms 33040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19024 KB Output is correct
2 Correct 55 ms 19224 KB Output is correct
3 Correct 78 ms 19272 KB Output is correct
4 Correct 157 ms 19448 KB Output is correct
5 Correct 58 ms 19024 KB Output is correct
6 Correct 114 ms 19396 KB Output is correct
7 Correct 62 ms 19308 KB Output is correct
8 Correct 56 ms 19024 KB Output is correct
9 Correct 75 ms 19024 KB Output is correct
10 Correct 55 ms 19252 KB Output is correct
11 Correct 63 ms 19244 KB Output is correct
12 Correct 44 ms 19024 KB Output is correct
13 Correct 106 ms 19280 KB Output is correct
14 Correct 66 ms 19280 KB Output is correct
15 Correct 81 ms 19452 KB Output is correct
16 Correct 31 ms 19024 KB Output is correct
17 Correct 84 ms 19352 KB Output is correct
18 Correct 61 ms 19120 KB Output is correct
19 Correct 65 ms 19112 KB Output is correct
20 Correct 359 ms 19280 KB Output is correct
21 Correct 242 ms 19328 KB Output is correct
22 Correct 52 ms 19024 KB Output is correct
23 Correct 114 ms 19256 KB Output is correct
24 Correct 74 ms 19248 KB Output is correct
25 Correct 87 ms 19248 KB Output is correct
26 Correct 47 ms 19240 KB Output is correct
27 Correct 335 ms 19392 KB Output is correct
28 Correct 269 ms 19376 KB Output is correct
29 Correct 217 ms 19280 KB Output is correct
30 Correct 32 ms 19024 KB Output is correct
31 Correct 162 ms 19280 KB Output is correct
32 Correct 232 ms 19280 KB Output is correct
33 Execution timed out 2058 ms 27720 KB Time limit exceeded
34 Halted 0 ms 0 KB -