제출 #87765

#제출 시각아이디문제언어결과실행 시간메모리
87765psmaoBitaro’s Party (JOI18_bitaro)C++14
14 / 100
1550 ms275956 KiB
#include <bits/stdc++.h>
using namespace std;

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 200050;

int n, m, q, cnt[maxn], in[maxn], gg[maxn];
VI adj[maxn], adj2[maxn];
pii dp[maxn][325], tmpa[325], tmpb[325];
bool g[maxn], banned[maxn];
int dist[maxn], vis[maxn], T;
queue<int> Q;

int dfs(int u)
{
	if(vis[u] == T) return dist[u];
	vis[u] = T; dist[u] = (banned[u] == true?-inf:0);
	for(auto p : adj2[u]) dist[u] = max(dist[u], dfs(p) + 1);
	return dist[u];
}
void bfs(int u)
{
	++ T;
	pf("%d\n", max(-1,dfs(u)));	
}
int main()
{
	#ifdef MPS
		freopen("03-140.txt","r",stdin);
		freopen("1.out","w",stdout);
	#endif
	sf("%d%d%d",&n,&m,&q);
	fo(i,1,m)
	{
		int u, v;
		sf("%d%d",&u,&v);
		adj[u].pb(v); in[v] ++;
		adj2[v].pb(u);
	} 
	fo(i,1,n) if(!in[i]) Q.push(i);
	while(!Q.empty())
	{
		int h = Q.front(); Q.pop();
		dp[h][++cnt[h]] = mp(h, 0);
		for(auto p : adj[h])
		{
			fo(j,1,cnt[h]) {tmpa[j] = dp[h][j]; tmpa[j].se ++;}
			fo(j,1,cnt[p]) tmpb[j] = dp[p][j];
			int p1 = 1, p2 = 1, num = 0;
			while(p1 <= cnt[h] && p2 <= cnt[p] && num < 324)
			{
				if(g[tmpa[p1].fi]) {++p1; continue;}
				if(g[tmpb[p2].fi]) {++p2; continue;}
				if(tmpa[p1].se > tmpb[p2].se) {g[tmpa[p1].fi] = true; dp[p][++num] = tmpa[p1++];}
				else {g[tmpb[p2].fi] = true; dp[p][++num] = tmpb[p2++];}
			}
			while(p1 <= cnt[h] && num < 324) {if(g[tmpa[p1].fi]) {++p1; continue;} g[tmpa[p1].fi] = true; dp[p][++num] = tmpa[p1++];}
			while(p2 <= cnt[p] && num < 324) {if(g[tmpb[p2].fi]) {++p2; continue;} g[tmpb[p2].fi] = true; dp[p][++num] = tmpb[p2++];}
			cnt[p] = num;
			fo(i,1,num) g[dp[p][i].fi] = false;
			if(!(--in[p])) Q.push(p);
		}
	}
	while(q-- )
	{
		int x, y;
		sf("%d%d",&x,&y);
		fo(i,1,y) {sf("%d",&gg[i]); banned[gg[i]] = true;}
		if(y > 324) bfs(x);
		else {fo(i,1,cnt[x]) if(!banned[dp[x][i].fi]) {pf("%d\n",dp[x][i].se); goto loop;} puts("-1"); loop:;}
		fo(i,1,y) banned[gg[i]] = false;
	}
	return 0;
}

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

bitaro.cpp: In function 'int main()':
bitaro.cpp:60:4: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  sf("%d%d%d",&n,&m,&q);
    ^
bitaro.cpp:64:5: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   sf("%d%d",&u,&v);
     ^
bitaro.cpp:95:5: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   sf("%d%d",&x,&y);
     ^
bitaro.cpp:96:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fo(i,1,y) {sf("%d",&gg[i]); banned[gg[i]] = true;}
                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...