Submission #1084909

# Submission time Handle Problem Language Result Execution time Memory
1084909 2024-09-07T08:11:33 Z DucNguyen2007 Bitaro’s Party (JOI18_bitaro) C++14
7 / 100
874 ms 524288 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=1e5+5;
const ll inf=2e18;
int n,m,q,dp[maxN+1],block,a[maxN+1],cnt[maxN+1];
vector<int> adj[maxN+1],topo;
vector<pii> vec[maxN+1],vt;
bool vis[maxN+1];
void dfs(int u)
{
    vis[u]=true;
    for(auto v:adj[u])
    {
        if(!vis[v])
        {
            dfs(v);
        }
    }
    topo.push_back(u);
}
void meg(int u,int v)
{
    int i=0,j=0;
    for(auto i:vec[u])
    {
        vis[i.fi]=false;
    }
    for(auto i:vec[v])
    {
        vis[i.fi]=false;
    }
    while(i<vec[u].size()&&j<vec[v].size()&&vt.size()<block)
    {
        while(i<vec[u].size()&&vis[vec[u][i].fi])
        {
            i++;
        }
        while(j<vec[v].size()&&vis[vec[v][j].fi])
        {
            j++;
        }
        if(i>=vec[u].size()||j>=vec[v].size())
        {
            break;
        }
        int p1=vec[u][i].se,p2=vec[v][j].se;
        if(p1+1>p2)
        {
            vt.push_back({vec[u][i].fi,p1+1});
            vis[vec[u][i].fi]=true;
            i++;
        }
        else
        {
            vt.push_back({vec[v][j].fi,p2});
            vis[vec[v][j].fi]=true;
            j++;
        }
    }
    while(i<vec[u].size()&&vt.size()<block)
    {
        while(i<vec[u].size()&&vis[vec[u][i].fi])
        {
            i++;
        }
        if(i>=vec[u].size())
        {
            break;
        }
        vt.push_back({vec[u][i].fi,vec[u][i].se+1});
        i++;
    }
    while(j<vec[v].size()&&vt.size()<block)
    {
        while(j<vec[v].size()&&vis[vec[v][j].fi])
        {
            j++;
        }
        if(j>=vec[v].size())
        {
            break;
        }
        vt.push_back({vec[v][j].fi,vec[v][j].se});
        j++;
    }
    vec[v]=vt;
    vt.clear();
}
void make()
{
    for(auto u:topo)
    {
        vec[u].push_back({u,0});
        for(auto v:adj[u])
        {
            //cout<<u<<" "<<v<<'\n';
            meg(u,v);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>q;
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
    }
    block=sqrt(n);
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
    memset(dp,0,sizeof(dp));
    reverse(topo.begin(),topo.end());
    make();
    while(q--)
    {
        int t,y;
        cin>>t>>y;
        if(y>=block)
        {
            for(int i=1;i<=n;i++)
            {
                dp[i]=0;
            }
        }
        for(int i=1;i<=y;i++)
        {
            int u;
            cin>>u;
            a[i]=u;
            dp[u]=INT_MIN;
            if(y<block)
            {
                cnt[u]++;
            }
        }
        if(y>=block)
        {
            for(auto u:topo)
            {
                for(auto v:adj[u])
                {
                    dp[v]=max(dp[v],dp[u]+1);
                }
            }
            if(dp[t]<0)
            {
                cout<<-1;
            }
            else cout<<dp[t];
        }
        else
        {
            int ans=-1;
            for(auto u:vec[t])
            {
                if(!cnt[u.fi])
                {
                    ans=u.se;
                    break;
                }
            }
            cout<<ans;
        }
        cout<<'\n';
        for(int i=1;i<=y;i++)
        {
            cnt[a[i]]=0;
        }
    }
}

Compilation message

bitaro.cpp: In function 'void meg(int, int)':
bitaro.cpp:37:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while(i<vec[u].size()&&j<vec[v].size()&&vt.size()<block)
      |           ~^~~~~~~~~~~~~~
bitaro.cpp:37:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while(i<vec[u].size()&&j<vec[v].size()&&vt.size()<block)
      |                            ~^~~~~~~~~~~~~~
bitaro.cpp:37:54: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |     while(i<vec[u].size()&&j<vec[v].size()&&vt.size()<block)
      |                                             ~~~~~~~~~^~~~~~
bitaro.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         while(i<vec[u].size()&&vis[vec[u][i].fi])
      |               ~^~~~~~~~~~~~~~
bitaro.cpp:43:16: 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 |         while(j<vec[v].size()&&vis[vec[v][j].fi])
      |               ~^~~~~~~~~~~~~~
bitaro.cpp:47:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         if(i>=vec[u].size()||j>=vec[v].size())
      |            ~^~~~~~~~~~~~~~~
bitaro.cpp:47: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]
   47 |         if(i>=vec[u].size()||j>=vec[v].size())
      |                              ~^~~~~~~~~~~~~~~
bitaro.cpp:65:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     while(i<vec[u].size()&&vt.size()<block)
      |           ~^~~~~~~~~~~~~~
bitaro.cpp:65:37: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   65 |     while(i<vec[u].size()&&vt.size()<block)
      |                            ~~~~~~~~~^~~~~~
bitaro.cpp:67:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         while(i<vec[u].size()&&vis[vec[u][i].fi])
      |               ~^~~~~~~~~~~~~~
bitaro.cpp:71:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         if(i>=vec[u].size())
      |            ~^~~~~~~~~~~~~~~
bitaro.cpp:78:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     while(j<vec[v].size()&&vt.size()<block)
      |           ~^~~~~~~~~~~~~~
bitaro.cpp:78:37: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   78 |     while(j<vec[v].size()&&vt.size()<block)
      |                            ~~~~~~~~~^~~~~~
bitaro.cpp:80:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         while(j<vec[v].size()&&vis[vec[v][j].fi])
      |               ~^~~~~~~~~~~~~~
bitaro.cpp:84:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |         if(j>=vec[v].size())
      |            ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5464 KB Output is correct
2 Correct 2 ms 5464 KB Output is correct
3 Correct 3 ms 5468 KB Output is correct
4 Correct 2 ms 5420 KB Output is correct
5 Correct 5 ms 5980 KB Output is correct
6 Correct 4 ms 5832 KB Output is correct
7 Correct 3 ms 5980 KB Output is correct
8 Correct 4 ms 5980 KB Output is correct
9 Correct 4 ms 5980 KB Output is correct
10 Correct 4 ms 5980 KB Output is correct
11 Correct 4 ms 5980 KB Output is correct
12 Correct 4 ms 5948 KB Output is correct
13 Correct 3 ms 5980 KB Output is correct
14 Correct 3 ms 5900 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 3 ms 5980 KB Output is correct
17 Correct 4 ms 5976 KB Output is correct
18 Correct 4 ms 5980 KB Output is correct
19 Correct 4 ms 5976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5464 KB Output is correct
2 Correct 2 ms 5464 KB Output is correct
3 Correct 3 ms 5468 KB Output is correct
4 Correct 2 ms 5420 KB Output is correct
5 Correct 5 ms 5980 KB Output is correct
6 Correct 4 ms 5832 KB Output is correct
7 Correct 3 ms 5980 KB Output is correct
8 Correct 4 ms 5980 KB Output is correct
9 Correct 4 ms 5980 KB Output is correct
10 Correct 4 ms 5980 KB Output is correct
11 Correct 4 ms 5980 KB Output is correct
12 Correct 4 ms 5948 KB Output is correct
13 Correct 3 ms 5980 KB Output is correct
14 Correct 3 ms 5900 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 3 ms 5980 KB Output is correct
17 Correct 4 ms 5976 KB Output is correct
18 Correct 4 ms 5980 KB Output is correct
19 Correct 4 ms 5976 KB Output is correct
20 Correct 81 ms 8572 KB Output is correct
21 Correct 93 ms 8608 KB Output is correct
22 Correct 83 ms 8636 KB Output is correct
23 Correct 82 ms 8528 KB Output is correct
24 Correct 586 ms 343244 KB Output is correct
25 Correct 654 ms 358092 KB Output is correct
26 Correct 617 ms 356272 KB Output is correct
27 Runtime error 874 ms 524288 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5464 KB Output is correct
2 Correct 2 ms 5464 KB Output is correct
3 Correct 3 ms 5468 KB Output is correct
4 Correct 2 ms 5420 KB Output is correct
5 Correct 5 ms 5980 KB Output is correct
6 Correct 4 ms 5832 KB Output is correct
7 Correct 3 ms 5980 KB Output is correct
8 Correct 4 ms 5980 KB Output is correct
9 Correct 4 ms 5980 KB Output is correct
10 Correct 4 ms 5980 KB Output is correct
11 Correct 4 ms 5980 KB Output is correct
12 Correct 4 ms 5948 KB Output is correct
13 Correct 3 ms 5980 KB Output is correct
14 Correct 3 ms 5900 KB Output is correct
15 Correct 3 ms 5724 KB Output is correct
16 Correct 3 ms 5980 KB Output is correct
17 Correct 4 ms 5976 KB Output is correct
18 Correct 4 ms 5980 KB Output is correct
19 Correct 4 ms 5976 KB Output is correct
20 Correct 81 ms 8572 KB Output is correct
21 Correct 93 ms 8608 KB Output is correct
22 Correct 83 ms 8636 KB Output is correct
23 Correct 82 ms 8528 KB Output is correct
24 Correct 586 ms 343244 KB Output is correct
25 Correct 654 ms 358092 KB Output is correct
26 Correct 617 ms 356272 KB Output is correct
27 Runtime error 874 ms 524288 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -