QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#402500#1454. Um nik's Algorithmdo_while_trueWA 0ms3872kbC++202.5kb2024-04-30 17:46:412024-04-30 17:46:42

Judging History

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

  • [2024-04-30 17:46:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3872kb
  • [2024-04-30 17:46:41]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<array>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
	r=0;bool w=0;char ch=getchar();
	while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
	while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
	return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int N=2000010;
mt19937 rnd(12321);
int A,B,m;
vpii eg[N];
int L[N],R[N];
int pos[N],pre[N],dis[N],ban[N];
int ans;
int solve(){
	queue<int>q;
	for(int i=1;i<=A;i++)dis[i]=N,pos[i]=pre[i]=ban[i]=0;
	for(int i=1;i<=A;i++)
		if(!R[i]){
			q.push(i);
			dis[i]=1;
		}
	while(!q.empty()){
		int x=q.front();q.pop();
		for(auto i:eg[x]){
			int y=i.fi;
			if(ban[y])continue;
			if(!L[y]){
				pos[x]=y;
				ban[y]=1;
				break;
			}
			int t=L[y];
			if(dis[t]>dis[x]+1){
				dis[t]=dis[x]+1;
				pre[t]=x;
				q.push(t);
			}
		}
	}
	int md=N;
	for(int i=1;i<=A;i++)if(pos[i])cmin(md,dis[i]);
	for(int i=1;i<=A;i++){
		if(pos[i]){
			int x=i,lst=pos[i];
			while(x){
				int tmp=R[x];
				R[x]=lst;
				L[lst]=x;
				lst=tmp;
				x=pre[x];
			}
			++ans;
		}
	}
	if(md==N)return 0;
	return 1;
}
signed main(){
	#ifdef do_while_true
		assert(freopen("data.in","r",stdin));
		assert(freopen("data.out","w",stdout));
	#endif
	read(A,B,m);
	for(int i=1;i<=m;i++){
		int u,v;read(u,v);
		eg[u].pb(v,i);
	}
	while(1.0*clock()/CLOCKS_PER_SEC<3.3){
		if(!solve())
			break;
	}
	cout<<ans<<'\n';
	for(int i=1;i<=A;i++)if(R[i])
		for(auto [j,id]:eg[i])
			if(j==R[i]){
				cout<<id<<'\n';
				break;
			}
    #ifdef do_while_true
//		cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
	#endif
	return 0;
}

詳細信息

Test #1:

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

input:

3 2 4
1 1
2 1
3 1
3 2

output:

2
1
4

result:

ok answer: 2, maximum: 2

Test #2:

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

input:

20 20 20
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
16 16
17 17
18 18
19 19
20 20

output:

20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

result:

ok answer: 20, maximum: 20

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3872kb

input:

1000 1000 10000
988 405
844 805
40 354
416 591
520 704
697 24
315 386
122 390
991 213
506 14
309 298
26 829
329 63
787 91
971 703
805 699
624 645
121 181
841 741
473 84
258 116
490 753
725 603
265 302
869 71
611 507
59 292
11 532
117 61
192 600
650 342
204 580
687 675
670 407
637 622
569 236
728 476...

output:

1000
205
737
383
8889
137
819
776
2426
1620
233
28
1840
845
1534
1401
459
1077
70
454
1699
8784
1816
598
509
75
12
1332
83
41
746
244
2718
1272
240
697
324
2027
195
759
3
7582
1520
215
838
279
2182
204
297
550
1182
2907
45
1645
4666
3959
105
318
1022
27
187
234
1031
216
7092
1484
1829
157
153
957
50...

result:

wrong output format Unexpected end of file - int32 expected