제출 #500115

#제출 시각아이디문제언어결과실행 시간메모리
500115kamalsharmaa9Bitaro’s Party (JOI18_bitaro)C++14
0 / 100
1160 ms524292 KiB
#include<bits/stdc++.h>
#include <cstdio>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define N               100050
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

const int B = 150;
int not_taken[N];
vector<int>gr[N];
vector<int>grr[N];
int dp[N];
vector<pii>dist[N];

int32_t main()
{
  c_p_c();
  int n, m, q;
  cin >> n >> m >> q;
  for (int i = 1; i <= m; i++)
  {
    int a, b;
    cin >> a >> b;
    gr[a].pb(b);
    grr[b].pb(a);
  }

///// precomputation
  for (int i = 1; i <= n; i++)
  {
    int node = i;
    vector<pii>child_and_dist;
    for (auto child : grr[node])
    {
      for (auto j : dist[child])
      {
        child_and_dist.pb({j.ff + 1, j.ss});
      }
    }
    child_and_dist.pb({0, node});
    int num_taken = 0;
    sort(child_and_dist.begin(), child_and_dist.end(), greater<pii>());
    map<int, int>rep;
    for (int i = 0; i < child_and_dist.size() && num_taken < B; i++)
    {
      if (rep.find(child_and_dist[i].ss) == rep.end())
      {
        num_taken++;
        dist[node].pb({child_and_dist[i]});
        rep[child_and_dist[i].ss] = 1;
      }
    }
  }


  while (q--)
  {
    int p, q;
    cin >> p >> q;
    vector<int>not_take;
    for (int i = 1; i <= q; i++)
    {
      int r; cin >> r;
      not_take.pb(r);
      not_taken[r] = 1;
    }
    ///////////////////////////
    if (q <= B)
    {
      int ans = -1;

      for (auto i : dist[p])
      {
        if (not_taken[i.second] || i.second==p)
          continue;
        ans = i.first;
        break;
      }
      cout << ans << '\n';
    }
    else
    {
      for (int i = 1; i <= p; i++)
      {
        dp[i] = 0;
      }
      for (int i = 1; i <= p - 1; i++)
      {
        if (not_taken[i] && dp[i] == 0)
          continue;
        for (auto child : gr[i])
        {
          dp[child] = max(dp[child], dp[i] + 1);
        }
      }
      cout << dp[p] << '\n';
    }
    for (auto i : not_take)
      not_taken[i] = 0;

  }





}

컴파일 시 표준 에러 (stderr) 메시지

bitaro.cpp: In function 'int32_t main()':
bitaro.cpp:71:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for (int i = 0; i < child_and_dist.size() && num_taken < B; i++)
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp: In function 'void c_p_c()':
bitaro.cpp:30:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   freopen("input.txt", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   freopen("output.txt", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...