Submission #1021688

#TimeUsernameProblemLanguageResultExecution timeMemory
1021688NoLoveBitaro’s Party (JOI18_bitaro)C++14
0 / 100
7 ms7972 KiB
/** * author : Lăng Trọng Đạt * created: 12-07-2024 **/ #include <bits/stdc++.h> using namespace std; #ifndef LANG_DAT #define db(...) ; #endif // LANG_DAT #define int long long #define mp make_pair #define f first #define se second #define pb push_back #define all(v) (v).begin(), (v).end() using pii = pair<int, int>; using vi = vector<int>; #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++) void mx(int& a, int b) { if (b > a) a = b; } void mi(int& a, int b) { if (b < a) a = b; } #define si(x) (int)(x.size()) const int INF = 1e18; const int MOD = 1e9 + 7; const int MAXN = 1e5 + 5; const int B = 100; vector<int> adj[MAXN]; int g[MAXN], in[MAXN]; int n, m, q, a, b; vector<pii> len[MAXN]; // {end node, longest length} bool block[MAXN]; int dp[MAXN]; void dfs(int v, int type) { dp[v] = -2; for (int u : adj[v]) { if (type == 1) { if (dp[u] == -1) dfs(u, type); if (dp[u] != -2) mx(dp[v], dp[u] + 1); } else if (dp[u] != -1) { dfs(u, type); } } if (!block[v]) mx(dp[v], 0); if (type == 0) dp[v] = -1; } int32_t main() { cin.tie(0)->sync_with_stdio(0); if (fopen("hi.inp", "r")) { freopen("hi.inp", "r", stdin); // freopen("hi.out", "w", stdout); } cin >> n >> m >> q; FOR(i, 1, m) { cin >> a >> b; adj[b].push_back(a); in[a]++; } vector<int> node; FOR(i, 1, n) if (in[i] == 0) node.push_back(i); vector<int> order; while (si(node)) { int v = node.back(); node.pop_back(); order.push_back(v); for (int u : adj[v]) { if (--in[u] == 0) { node.push_back(u); } } } reverse(all(order)); vector<int> pos(n + 1, -1); for (int v : order) { len[v].push_back({v, 0}); for (int u : adj[v]) { for (auto[a, b] : len[u]) { if (pos[a] != -1) mx(len[v][pos[a]].se, b + 1); else len[v].push_back({a, b + 1}); } sort(all(len[v]), [](pii& a, pii& b) -> bool {return a.se > b.se;}); while (si(len[v]) > B) {pos[len[v].back().f] = -1; len[v].pop_back(); } FOR(id, 0, si(len[v]) - 1) { pos[len[v][id].f] = id; } } FOR(id, 0, si(len[v]) - 1) { pos[len[v][id].f] = -1; } } // FOR(i, 1, n) { // db(i, len[i]); // } memset(dp, -1, sizeof(dp)); FOR(i, 1, q) { int source, t; cin >> source >> t; vector<int> c(t); for (int& v : c) { cin >> v; block[v] = 1; } db(source, t) int ans = -1; if (t > B) { dfs(source, 1); ans = dp[source]; dfs(source, 0); } else { for (auto[u, l] : len[source]) { if (!block[u]) { ans = l; break; } } } cout << ans << "\n"; for (int v : c) { block[v] = 0; } } }

Compilation message (stderr)

bitaro.cpp: In function 'int32_t main()':
bitaro.cpp:18:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
bitaro.cpp:58:5: note: in expansion of macro 'FOR'
   58 |     FOR(i, 1, m) {
      |     ^~~
bitaro.cpp:18:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
bitaro.cpp:65:5: note: in expansion of macro 'FOR'
   65 |     FOR(i, 1, n) if (in[i] == 0) node.push_back(i);
      |     ^~~
bitaro.cpp:82:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   82 |             for (auto[a, b] : len[u]) {
      |                      ^
bitaro.cpp:18:31: warning: unnecessary parentheses in declaration of 'id' [-Wparentheses]
   18 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
bitaro.cpp:88:13: note: in expansion of macro 'FOR'
   88 |             FOR(id, 0, si(len[v]) - 1) {
      |             ^~~
bitaro.cpp:18:31: warning: unnecessary parentheses in declaration of 'id' [-Wparentheses]
   18 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
bitaro.cpp:92:9: note: in expansion of macro 'FOR'
   92 |         FOR(id, 0, si(len[v]) - 1) {
      |         ^~~
bitaro.cpp:18:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
bitaro.cpp:101:5: note: in expansion of macro 'FOR'
  101 |     FOR(i, 1, q) {
      |     ^~~
bitaro.cpp:116:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  116 |             for (auto[u, l] : len[source]) {
      |                      ^
bitaro.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         freopen("hi.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...