QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#77387 | #1359. Setting Maps | ExplodingKonjac | WA | 2ms | 3416kb | C++17 | 6.0kb | 2023-02-14 16:03:40 | 2023-02-14 16:03:42 |
Judging History
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);
}
int 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: 0
Wrong Answer
time: 2ms
memory: 3416kb
input:
3 2 5 1 3 1 60 35 1 2 2 3
output:
1 3
result:
wrong answer Given vertex set from user output does not cover k vertices in some path