QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#28028#1359. Setting MapsWu_RenWA 3ms3828kbC++171.7kb2022-04-11 17:22:482022-04-29 08:32:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-29 08:32:11]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3828kb
  • [2022-04-11 17:22:48]
  • 提交

answer

#include <bits/stdc++.h>
typedef long long ll;
const ll inf=3e9;
using namespace std;
int n,m,K,E,B,in[210][10],out[210][10],head[2410],o=1,dep[2410],cur[2410],S,T,cnt=0;
vector<int>pt;
struct edge{
	int to,link;
	ll w;
}e[200000];
void add_edge(int u,int v,ll w){
	e[++o]={v,head[u],w},head[u]=o;
	e[++o]={u,head[v],0},head[v]=o;
}
queue<int>q;
bool bfs(){
	memset(dep,0,sizeof(dep)),memcpy(cur,head,sizeof(head));
	dep[S]=1,q.push(S);
	while(q.size()){
		int u=q.front();q.pop();
		for(int i=head[u],v;i;i=e[i].link) if(!dep[v=e[i].to]&&e[i].w){
			dep[v]=dep[u]+1,q.push(v);
		}
	}
	return dep[T];
}
ll dfs(int u,ll in){
	if(u==T) return in;
	ll out=0;
	for(int &i=cur[u],v;i;i=e[i].link) if(dep[v=e[i].to]==dep[u]+1&&e[i].w){
		ll res=dfs(v,min(in,e[i].w));
		e[i].w-=res,e[i^1].w+=res;
		in-=res;
		out+=res;
		if(!in) break;
	}
	return out;
} 
int main(){
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=K;j++) in[i][j]=++cnt;
		for(int j=1;j<=K;j++) out[i][j]=++cnt;
	}
	S=++cnt,T=++cnt;
	scanf("%d%d",&B,&E);
	add_edge(S,in[B][1],inf);
	for(int j=1;j<=K;j++) add_edge(out[E][j],T,inf);
	for(int i=1,C;i<=n;i++){
		scanf("%d",&C);
		for(int j=1;j<K;j++) add_edge(in[i][j],out[i][j+1],inf);
		for(int j=1;j<=K;j++) add_edge(in[i][j],out[i][j],C);
	}
	while(m--){
		int u,v;
		scanf("%d%d",&u,&v);
		for(int j=1;j<=K;j++) add_edge(out[u][j],in[v][j],inf);
	}
	ll ans=0;
	while(bfs()) ans+=dfs(S,inf);
	if(ans>=inf) puts("-1"),exit(0);
	for(int i=1;i<=n;i++){
		bool fl=0;
		for(int j=1;j<=K;j++) if((!!dep[in[i][j]])^(!!dep[out[i][j]])) fl=1;
		if(fl) pt.push_back(i);
	}
	printf("%d\n",pt.size());
	for(int i:pt) printf("%d ",i);puts("");
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3804kb

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: 3ms
memory: 3728kb

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: 3ms
memory: 3828kb

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:

7
1 5 6 7 8 9 10 

result:

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