QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#77388#1359. Setting MapsExplodingKonjacRE 2ms5336kbC++176.0kb2023-02-14 16:04:042023-02-14 16:04:08

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-14 16:04:08]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:5336kb
  • [2023-02-14 16:04:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
//#define OPENIOBUF

namespace FastIO
{

class FastIOBase
{
 protected:
#ifdef OPENIOBUF
	static const int BUFSIZE=1<<22;
	char buf[BUFSIZE+1];
	int buf_p=0;
#endif
	FILE *target;
 public:
#ifdef OPENIOBUF
	virtual void flush()=0;
#endif
	FastIOBase(FILE *f): target(f){}
	~FastIOBase()=default;
};

class FastOutput: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
		{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
 protected:
	inline void __putc(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE)flush();
#else
		putc(x,target);
#endif
	}
	template<typename T>
	inline void __write(T x)
	{
		static char stk[64],*top;top=stk;
		if(x<0) return __putc('-'),__write(-x);
		do *(top++)=x%10,x/=10; while(x);
		for(;top!=stk;__putc(*(--top)+'0'));
	}
 public:
	FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
	inline void setTarget(FILE *f) { this->flush(),target=f; }
	~FastOutput(){ flush(); }
#else
	inline void setTarget(FILE *f) { target=f; }
#endif
	template<typename ...T>
	inline void writesp(const T &...x)
		{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
	template<typename ...T>
	inline void writeln(const T &...x)
		{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
	inline FastOutput &operator <<(char x)
		{ return __putc(x),*this; }
	inline FastOutput &operator <<(const char *s)
		{ for(;*s;__putc(*(s++)));return *this; }
	inline FastOutput &operator <<(const string &s)
		{ return (*this)<<s.c_str(); }
	template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
	inline FastOutput &operator <<(const T &x)
		{ return __write(x),*this; }
}qout;

class FastInput: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
		{ buf[fread(buf,1,BUFSIZE,target)]='\0',buf_p=0; }
#endif
 protected:
	inline char __getc()
	{
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		return buf[buf_p++];
#else
		return getc(target);
#endif
	}
 public:
#ifdef OPENIOBUF
	FastInput(FILE *f=stdin): FastIOBase(f){ buf_p=BUFSIZE; }
	inline void setTarget(FILE *f) { this->flush(),target=f; }
#else
	FastInput(FILE *f=stdin): FastIOBase(f){}
	inline void setTarget(FILE *f) { target=f; }
#endif
	inline char getchar() { return __getc(); }
	template<typename ...T>
	inline void read(T &...x)
		{ initializer_list<int>{(this->operator>>(x),0)...}; }
	inline FastInput &operator >>(char &x)
		{ while(isspace(x=__getc()));return *this; }
	template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
	inline FastInput &operator >>(T &x)
	{
		static char ch,sym;x=sym=0;
		while(isspace(ch=__getc()));
		if(ch=='-') sym=1,ch=__getc();
		for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
		return sym?x=-x:x,*this;
	}
	inline FastInput &operator >>(char *s)
	{
		while(isspace(*s=__getc()));
		for(;!isspace(*s) && *s && ~*s;*(++s)=__getc());
		return *s='\0',*this;
	}
	inline FastInput &operator >>(string &s)
	{
		char str_buf[(1<<8)+1],*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=__getc()));
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=__getc()) && *p && ~*p;p++);
			*p='\0',s.append(str_buf);
			if(p!=buf_end) break;
		}
		return *this;
	}
}qin;

} // namespace FastIO
using namespace FastIO;

using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;
constexpr LL INF=1e16;

#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#else
#define FILEIO(file)
#endif

namespace NetworkFlow
{
	
template<int MAXN,int MAXM,typename FlowT=int,
		 typename=typename enable_if<is_integral<FlowT>::value>::type>
class MFGraph
{
 public:
	struct Edge{ int to,nxt;FlowT w; }e[2*MAXM+5];
	int head[MAXN+5];
 private:
	int cnt,headd[MAXN+5],dep[MAXN+5];
	inline void __addEdge(int u,int v,FlowT w)
		{ e[++cnt]=(Edge){v,head[u],w},head[u]=cnt; }
	bool bfs(int S,int T)
	{
		static int hd,tl,q[MAXN+5];
		memset(dep,0,sizeof(dep));
		memcpy(headd,head,sizeof(head));
		q[hd=tl=1]=S,dep[S]=1;
		for(int u=q[hd];(hd++)<=tl;u=q[hd])
			for(int i=head[u],v;v=e[i].to,i;i=e[i].nxt)
				if(e[i].w && !dep[v])
					dep[v]=dep[u]+1,q[++tl]=v;
		return dep[T];
	}
	FlowT dfs(int u,int T,FlowT flow=numeric_limits<FlowT>::max())
	{
		if(u==T || !flow) return flow;
		FlowT res=flow;
		for(int &i=headd[u],v;v=e[i].to,i;i=e[i].nxt)
			if(e[i].w && dep[v]==dep[u]+1)
			{
				FlowT c=dfs(v,T,min(res,e[i].w));
				e[i].w-=c,e[i^1].w+=c;
				if(!(res-=c)) break;
			}
		if(res==flow) dep[u]=0;
		return flow-res;
	}
 public:
	MFGraph(){ clear(); }
	inline void clear()
		{ cnt=1,memset(head,0,sizeof(head)); }
	inline void addEdge(int u,int v,FlowT w)
		{ __addEdge(u,v,w),__addEdge(v,u,0); }
	inline FlowT maxFlow(int S,int T)
	{
		FlowT res=0;
		while(bfs(S,T)) res+=dfs(S,T);
		return res;
	}
};

} // namespace NetworkFlow
using namespace NetworkFlow;

int n,m,k,S,T,a[205],nn,pi[205][10],po[205][10];
bool vis[205];
MFGraph<10000,1000000,LL> g;
void dfs(int u)
{
	if(vis[u]) return;
	vis[u]=true;
	for(int i=g.head[u];i;i=g.e[i].nxt)
		if(g.e[i].w) dfs(g.e[i].to);
}
int main()
{
	qin>>n>>m>>k;
	qin>>S>>T;
	for(int i=1;i<=n;i++)
	{
		qin>>a[i];
		for(int j=0;j<k;j++) pi[i][j]=++nn,po[i][j]=++nn;
		for(int j=1;j<k;j++) g.addEdge(pi[i][j-1],pi[i][j],INF);
		for(int j=1;j<k;j++) g.addEdge(pi[i][j-1],po[i][j],INF);
		for(int j=0;j<k;j++) g.addEdge(pi[i][j],po[i][j],a[i]);
	}
	for(int i=1,u,v;i<=m;i++)
	{
		qin>>u>>v;
		for(int j=0;j<k;j++) g.addEdge(po[u][j],pi[v][j],INF);
	}
	LL res=g.maxFlow(pi[S][0],po[T][k-1]);
	if(res>=INF) return qout<<-1,0;
	dfs(pi[S][0]);
	vector<int> ans;
	for(int i=1;i<=n;i++)
	{
		bool fl=false;
		for(int j=0;j<k;j++)
			if(vis[pi[i][j]]>vis[po[i][j]]) fl=true;
		if(fl) ans.push_back(i);
	}
	qout.writeln(ans.size());
	for(auto &i: ans) qout<<i<<' ';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5336kb

input:

3 2 5
1 3
1 60 35
1 2
2 3

output:

-1

result:

ok answer = IMPOSSIBLE

Test #2:

score: 0
Accepted
time: 2ms
memory: 3484kb

input:

7 11 1
1 7
100 5 7 16 11 12 100
1 2
1 3
1 4
1 5
2 3
2 6
3 6
4 3
4 7
5 7
6 7

output:

4
2 3 4 5 

result:

ok answer = 39

Test #3:

score: 0
Accepted
time: 2ms
memory: 3476kb

input:

11 17 2
1 11
1000 10 10 10 10 10 10 10 10 10 1000
1 2
1 3
1 4
1 5
1 6
2 7
3 7
4 7
5 8
6 8
7 8
7 9
7 10
8 9
8 11
9 11
10 11

output:

6
5 6 7 8 9 10 

result:

ok answer = 60

Test #4:

score: 0
Accepted
time: 2ms
memory: 3412kb

input:

2 2 2
2 1
100 200
1 2
2 1

output:

2
1 2 

result:

ok answer = 300

Test #5:

score: 0
Accepted
time: 0ms
memory: 3396kb

input:

5 5 5
1 5
1 1 1 1 1
1 2
2 3
3 4
4 5
1 5

output:

-1

result:

ok answer = IMPOSSIBLE

Test #6:

score: 0
Accepted
time: 2ms
memory: 3536kb

input:

100 120 5
1 5
5367720 2854323 1799056 9744604 3215334 7580413 6269402 3208439 8812449 3297484 2047196 4044341 7514502 2928715 9335004 3935096 6660663 3356480 4801491 5786147 895995 6710240 222342 4469390 1543213 6678041 8838445 6741919 8138951 5273670 8983795 5131484 4245746 7460466 8357966 8464419 ...

output:

-1

result:

ok answer = IMPOSSIBLE

Test #7:

score: 0
Accepted
time: 1ms
memory: 5316kb

input:

2 1 5
1 2
10 10
1 2

output:

-1

result:

ok answer = IMPOSSIBLE

Test #8:

score: -100
Runtime Error

input:

154 304 2
67 7
10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 100000...

output:


result: