Submission #68649

# Submission time Handle Problem Language Result Execution time Memory
68649 2018-08-17T19:02:24 Z TadijaSebez Bitaro’s Party (JOI18_bitaro) C++11
0 / 100
11 ms 9720 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
const int N=100050;
const int inf=1e9+7;
const int S=100;
vector<int> E[N];
vector<pair<int,int> > dp[N];
set<pair<int,int> > pq;
map<int,int> dist[N];
bool was[N];
int tmp[N];
int main()
{
	int n,m,q,i,j,u,v,k;
	scanf("%i %i %i",&n,&m,&q);
	for(i=1;i<=m;i++) scanf("%i %i",&u,&v),E[v].pb(u);
	for(i=1;i<=m;i++)
	{
		pq.insert(mp(0,i));
		for(j=0;j<E[i].size();j++)
		{
			v=E[i][j];
			for(k=0;k<dp[v].size();k++)
			{
				int h=dp[v][k].second;
				if(dist[i].count(h))
				{
                    if(dist[i][h]<dp[v][k].first+1)
                    {
						pq.erase(mp(dist[i][h],h));
						dist[i][h]=dp[v][k].first+1;
						pq.insert(mp(dist[i][h],h));
                    }
				}
				else pq.insert(mp(dp[v][k].first+1,dp[v][k].second)),dist[i][h]=dp[v][k].first+1;
				if(pq.size()>=S) pq.erase(pq.begin());
			}
		}
		while(pq.size()) dp[i].pb(*pq.begin()),pq.erase(pq.begin());
	}
	while(q--)
	{
		int sz,st;
		vector<int> x;
		scanf("%i %i",&st,&sz);
		x.resize(sz);
		for(i=0;i<sz;i++) scanf("%i",&x[i]),was[x[i]]=1;
		if(sz>=S)
		{
			for(i=1;i<=st;i++)
			{
				if(was[i]) tmp[i]=-inf;
				else tmp[i]=0;
				for(j=0;j<E[i].size();j++) tmp[i]=max(tmp[i],tmp[E[i][j]]+1);
			}
			if(tmp[st]>=0) printf("%i\n",tmp[st]);
			else printf("-1\n");
		}
		else
		{
			int ans=-1;
			for(i=0;i<dp[st].size();i++) if(!was[dp[st][i].second]) ans=dp[st][i].first;
			printf("%i\n",ans);
		}
		for(i=0;i<sz;i++) was[x[i]]=0;
	}
	return 0;
}

Compilation message

bitaro.cpp: In function 'int main()':
bitaro.cpp:23:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<E[i].size();j++)
           ~^~~~~~~~~~~~
bitaro.cpp:26:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(k=0;k<dp[v].size();k++)
            ~^~~~~~~~~~~~~
bitaro.cpp:57:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(j=0;j<E[i].size();j++) tmp[i]=max(tmp[i],tmp[E[i][j]]+1);
             ~^~~~~~~~~~~~
bitaro.cpp:65:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(i=0;i<dp[st].size();i++) if(!was[dp[st][i].second]) ans=dp[st][i].first;
            ~^~~~~~~~~~~~~~
bitaro.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i %i",&n,&m,&q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:19:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1;i<=m;i++) scanf("%i %i",&u,&v),E[v].pb(u);
                    ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
bitaro.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i",&st,&sz);
   ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:50:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(i=0;i<sz;i++) scanf("%i",&x[i]),was[x[i]]=1;
                     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 9720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 9720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 9720 KB Output isn't correct
2 Halted 0 ms 0 KB -