QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397584#1359. Setting MapsLynkcatWA 4ms60592kbC++172.6kb2024-04-24 13:52:112024-04-24 13:52:12

Judging History

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

  • [2024-04-24 13:52:12]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:60592kb
  • [2024-04-24 13:52:11]
  • 提交

answer

#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define mod 998244353
#define sz(x) (int)((x).size())
#define int ll
//#define N
using namespace std;
const int N=1000005,M=1000005,inf=1e18;
struct edge
{
	int to,val,nxt;
	edge(int a=0,int b=0,int c=0)
	{
		to=a,val=b,nxt=c;
	}
}E[M<<1];
int cnt=1;
int hd[N],dis[N],q[N],cur[N];
int tot,S,T,ans;
void add(int x,int y,int w)
{
	E[++cnt].to=y;
	E[cnt].val=w;
	E[cnt].nxt=hd[x];
	hd[x]=cnt;
	
	E[++cnt].to=x;
	E[cnt].val=0;
	E[cnt].nxt=hd[y];
	hd[y]=cnt;
}
int bfs()
{
	int l=1,r=1;
	for (int i=1;i<=tot;i++) dis[i]=inf,cur[i]=hd[i];
	dis[S]=0;
	q[1]=S;
	while (l<=r)
	{
		int u=q[l++];
		for (int i=hd[u];i;i=E[i].nxt)
		{
			if (E[i].val&&dis[E[i].to]>dis[u]+1)
			{
				dis[E[i].to]=dis[u]+1;
				q[++r]=E[i].to;
			}
		}
	}
	return (dis[T]!=inf);
}
int dinic(int k,int liu)
{
	if (k==T) return liu;
	int res=liu;
	for (int i=cur[k];i&&res;i=E[i].nxt)
	{
		cur[k]=i;
		if (dis[E[i].to]==dis[k]+1&&E[i].val)
		{
			int c=dinic(E[i].to,min(res,E[i].val));
			res-=c;
			E[i].val-=c;
			E[i^1].val+=c;
			if (!res) break;
		}
	}
	return liu-res;
}
int n,m,K;
int id[205][15][2];
int vis[N];
int c[N];
void dfs(int k)
{
	vis[k]=1;
	for (int i=hd[k];i;i=E[i].nxt)
		if (i%2==0&&E[i].val&&!vis[E[i].to])
		{
			// cout<<k<<"->"<<E[i].to<<endl;
			dfs(E[i].to);
		}
}
void BellaKira()
{
	cin>>n>>m>>K;
	cin>>S>>T;
	for (int i=1;i<=n;i++)
		cin>>c[i];
	for (int i=1;i<=n;i++)
		for (int j=1;j<=K;j++)
			id[i][j][0]=++tot,id[i][j][1]=++tot;
	for (int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		for (int j=1;j<=K;j++)
			add(id[x][j][1],id[y][j][0],inf);
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=K;j++)
		{
			for (int k=j+1;k<=K;k++)
				add(id[i][j][0],id[i][k][1],inf);
		}
		for (int j=1;j<=K;j++) add(id[i][j][0],id[i][j][1],c[i]);
	}
	++tot,++tot;
	add(tot-1,id[S][1][0],inf);
	S=tot-1;
	add(id[T][K][1],tot,inf);
	T=tot;
	int ans=0;
	while (bfs()) ans+=dinic(S,inf);
	// cout<<"???"<<ans<<endl;
	if (ans==inf) cout<<"-1\n";
	else
	{
		dfs(S);
		poly g;
		for (int i=1;i<=n;i++)
		{
			int bl=0;
			for (int j=1;j<=K;j++)
				if (vis[id[i][j][0]]!=vis[id[i][j][1]]) bl=1;
			if (bl)
				g.push_back(i);
		}
		cout<<sz(g)<<'\n';
		for (auto u:g) cout<<u<<" ";
		cout<<'\n';
	}
}
signed main()
{
	IOS;
	cin.tie(0);
	int T=1;
	while (T--)
	{
		BellaKira();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 56852kb

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: 0ms
memory: 59948kb

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: -100
Wrong Answer
time: 4ms
memory: 60592kb

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:

9
1 3 4 5 6 7 8 9 10 

result:

wrong answer User answer is not optimal; judge: 60, user: 1080