Submission #384232

#TimeUsernameProblemLanguageResultExecution timeMemory
384232JerryLiu06Bitaro’s Party (JOI18_bitaro)C++11
0 / 100
2081 ms52952 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; #define pb push_back #define f first #define s second int N, M, Q, BLOCK; vector<int> radj[100010]; bool mark[100010]; bool busy[100010]; int dist[100010]; vector<pii> DP[100010]; vector<pii> merge(vector<pii> A, vector<pii> B) { vector<pii> res; int L = 0, R = 0; while (res.size() < BLOCK) { if (L < A.size() && R < B.size()) { if (A[L].f > B[R].f) { if (!mark[A[L].s]) res.pb(A[L]); mark[A[L].s] = true; L++; } else { if (!mark[B[R].s]) res.pb(B[R]); mark[B[R].s] = true; R++; } } else if (L < A.size()) { if (!mark[A[L].s]) res.pb(A[L]); mark[A[L].s] = true; L++; } else if (R < B.size()) { if (!mark[B[R].s]) res.pb(B[R]); mark[B[R].s] = true; R++; } else break; } for (pii P : res) mark[P.s] = false; return res; } void genDP(int X) { DP[X].pb({0, X}); for (int NXT : radj[X]) { vector<pii> V = DP[NXT]; for (int i = 0; i < V.size(); i++) V[i].f++; DP[X] = merge(DP[X], V); } } int BFS(int X) { queue<int> Q; Q.push(X); dist[X] = 0; int res = -1; while (!Q.empty()) { int CUR = Q.front(); Q.pop(); if (!busy[CUR]) res = max(res, dist[CUR]); for (int NXT : radj[CUR]) { dist[NXT] = max(dist[NXT], dist[CUR] + 1); Q.push(NXT); } } return res; } int CHECK(int X) { for (pii P : DP[X]) { if (!busy[P.s]) return P.f; } return -1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> M >> Q; BLOCK = sqrt(N); for (int i = 0; i < M; i++) { int A, B; cin >> A >> B; radj[B].pb(A); } for (int i = 1; i <= N; i++) genDP(i); for (int i = 0; i < Q; i++) { int T, Y; cin >> T >> Y; vector<int> V; for (int i = 0; i < Y; i++) { int X; cin >> X; V.pb(X); busy[X] = true; } if (Y >= BLOCK) cout << BFS(T) << "\n"; else cout << CHECK(T) << "\n"; for (int i : V) busy[i] = false; } }

Compilation message (stderr)

bitaro.cpp: In function 'std::vector<std::pair<int, int> > merge(std::vector<std::pair<int, int> >, std::vector<std::pair<int, int> >)':
bitaro.cpp:25:23: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     while (res.size() < BLOCK) {
      |            ~~~~~~~~~~~^~~~~~~
bitaro.cpp:26:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if (L < A.size() && R < B.size()) {
      |             ~~^~~~~~~~~~
bitaro.cpp:26:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if (L < A.size() && R < B.size()) {
      |                             ~~^~~~~~~~~~
bitaro.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         else if (L < A.size()) {
      |                  ~~^~~~~~~~~~
bitaro.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         else if (R < B.size()) {
      |                  ~~^~~~~~~~~~
bitaro.cpp:50:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   50 |     for (pii P : res) mark[P.s] = false; return res;
      |     ^~~
bitaro.cpp:50:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   50 |     for (pii P : res) mark[P.s] = false; return res;
      |                                          ^~~~~~
bitaro.cpp: In function 'void genDP(int)':
bitaro.cpp:59:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for (int i = 0; i < V.size(); i++) V[i].f++;
      |                         ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...