Submission #479692

#TimeUsernameProblemLanguageResultExecution timeMemory
479692MilosMilutinovicBitaro’s Party (JOI18_bitaro)C++14
7 / 100
2088 ms13944 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int M = 1000; vector<int> g[N], rg[N]; vector<pair<int, int>> all[N]; bool can[N]; int qId[N], dp[N]; void dfs1(int u) { for (int v : rg[u]) { dp[v] = max(dp[v], dp[u] + 1); } for (int v : rg[u]) { dfs1(v); } } int main() { int n, m, q; scanf("%d%d%d", &n, &m, &q); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); --u; --v; g[u].push_back(v); rg[v].push_back(u); } for (int u = 0; u < n; u++) { vector<pair<int, int>> Edges; Edges.push_back({0, u}); for (int v : rg[u]) { for (auto his : all[v]) { Edges.push_back({his.first + 1, his.second}); } } sort(Edges.begin(), Edges.end(), [&](pair<int, int> X, pair<int, int> Y) { if (X.second != Y.second) { return X.second < Y.second; } return X.first < Y.first; }); vector<pair<int, int>> edg; for (int i = 0; i < Edges.size(); i++) { if (i + 1 == Edges.size() || Edges[i].second != Edges[i + 1].second) { edg.push_back(Edges[i]); } } sort(edg.rbegin(), edg.rend()); for (int i = 0; i < edg.size(); i++) { if (all[u].size() + 1 <= M) { all[u].push_back(edg[i]); } } } /*for (int i = 0; i < n; i++) { printf("node %d: ", i); for (auto my : all[i]) { printf("%d ", my.first); } printf("\n"); }*/ for (int i = 0; i < n; i++) can[i] = true; for (int i = 0; i < n; i++) sort(g[i].begin(), g[i].end()); for (int i = 0; i < n; i++) sort(rg[i].rbegin(), rg[i].rend()); while (q--) { int st, qSz; scanf("%d%d", &st, &qSz); --st; for (int i = 0; i < qSz; i++) { scanf("%d", &qId[i]); --qId[i]; can[qId[i]] = false; } if (qSz >= M) { for (int i = 0; i < n; i++) dp[i] = 0; dfs1(st); int ans = -1; for (int i = 0; i < n; i++) { if (can[i]) ans = max(ans, dp[i]); else can[i] = true; } printf("%d\n", ans); } else { int ans = -1; for (auto d : all[st]) { if (can[d.second]) { ans = max(ans, d.first); } } for (int i = 0; i < qSz; i++) can[qId[i]] = true; printf("%d\n", ans); } } return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for (int i = 0; i < Edges.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
bitaro.cpp:49:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |    if (i + 1 == Edges.size() || Edges[i].second != Edges[i + 1].second) {
      |        ~~~~~~^~~~~~~~~~~~~~~
bitaro.cpp:54:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for (int i = 0; i < edg.size(); i++) {
      |                   ~~^~~~~~~~~~~~
bitaro.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  scanf("%d%d%d", &n, &m, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   scanf("%d%d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~
bitaro.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |   scanf("%d%d", &st, &qSz);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
bitaro.cpp:75:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |    scanf("%d", &qId[i]);
      |    ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...