首页 > 其他分享 >CF847J Students Initiation

CF847J Students Initiation

时间:2023-12-31 16:35:27浏览次数:27  
标签:Students mid CF847J write int Initiation ans check

题意

有 \(n\) 个人,\(m\) 对关系,要求每对关系中,有且仅有一个人给另外一个人送礼物,并且使送出礼物最多的人送的礼物尽可能少。并输出送礼物的方案。

Sol

二分答案,对于每个人向每个限制连 \(1\) 容量,每个限制向汇点连 \(1\) 容量。

Code


array <pii, N> isl;

bool check(int x, int n, int m) {
	G::cnt = 1, G::fir.fill(0);
	pii st(m + n + 1, m + n + 2);
	for (int i = 1; i <= m; i++) {
		G::_add(isl[i].fi, n + i, 1);
		G::_add(isl[i].se, n + i, 1);
		G::_add(n + i, st.se, 1);
	}
	for (int i = 1; i <= n; i++)
		G::_add(st.fi, i, x);
	return Mfl::dinic(st) == m;
}

array <int, N> _ans;

signed main() {
	int n = read(), m = read();
	for (int i = 1; i <= m; i++)
		isl[i] = make_pair(read(), read());
	if (!m) return puts("0"), 0;
	int l = 1, r = n;
	int ans = -1;
	while (l <= r) {
		int mid = (l + r) >> 1;
		/* write(l), putchar(32); */
		/* write(r), putchar(32); */
		/* write(mid), puts(""); */
		if (check(mid, n, m)) ans = mid, r = mid - 1;
		else l = mid + 1;
	}
	check(ans, n, m);
	for (int i = 1; i <= n; i++)
		for (int j = G::fir[i]; j; j = G::nex[j])
			if (G::to[j] > n && G::to[j] != n + m + 1 && !G::cap[j])
				_ans[G::to[j] - n] = i;
	write(ans), puts("");
	for (int i = 1; i <= m; i++) {
		int x, y; tie(x, y) = isl[i];
		/* write(_ans[i]), puts(""); */
		if (x != _ans[i]) swap(x, y);
		write(x), putchar(32);
		write(y), puts("");
	}
	return 0;
}

标签:Students,mid,CF847J,write,int,Initiation,ans,check
From: https://www.cnblogs.com/cxqghzj/p/17937636

相关文章

  • 初中英语优秀范文100篇-042Is It Good for Students to Play Video Games?学生玩游戏
    PDF格式公众号回复关键字:SHCZFW042记忆树1Videogameshavebecomemoreandmorepopularnow.翻译现在视频游戏变得越来越流行。简化记忆流行句子结构1主语(Subject):"Videogames"(电子游戏)是句子的主题,表示现在完成时态的承受者。2谓语(Predicate):"havebe......
  • 初中英语优秀范文100篇-038Should Students Make Firiends Online?学生应该在线交友吗
    PDF格式公众号回复关键字:SHCZFW038记忆树1Nowadays,manyteenagersshowagreatinterestinmakingfriendsonline.翻译现如今,许多青少年对于在网上交朋友表现出很大的兴趣。简化记忆兴趣句子结构1"Nowadays"是一个副词,表示这个句子描述的是现在的情景。2"man......
  • 19.Some people say:Face-to-face classes are a better option for college students
    Round1:PresentingPossibleCounterargumentsSpeaker1(StudentA):Hello,everyone!Theclaimthatface-to-faceclassesareabetteroptionthanonlineclassesisquitecommon.However,let'sconsidersomecounterarguments.Onemightarguethatonl......
  • College Students'Booklist
    CollegeStudents'BooklistAsisclearlyreflectedinthetableabove,thepercentageofthecollegestudents'booklist,from1992to2012.wecanseethereisabigchangeofcollegestudent'schoiceofbooksfrom1992to2012.Obviously,books......
  • [LeetCode] 1349. Maximum Students Taking Exam 参加考试的最大学生数
    Givena m *n matrix seats  thatrepresentseatsdistributions inaclassroom. Ifaseat is broken,itisdenotedby '#' characterotherwiseitisdenotedbya '.' character.Studentscanseetheanswersofthosesittingnexttothele......
  • Students-system开发步骤
    项目初始化新建文件夹,命名为students-system,注意这里的命名不得为中文或其他特殊字符npminit-y安装包npmijqueryexpressexpress-art-template新建文件夹新建public,views文件夹,public下新建img,js,css文件夹,目录如下:student-systemnode_modulespublicim......
  • Students-system开发步骤
    #Students-system开发步骤##项目初始化新建文件夹,命名为`students-system`,注意这里的命名不得为中文或其他特殊字符```shellnpminit-y```##安装包```shellnpmijqueryexpressexpress-art-template```##新建文件夹新建public,views文件夹,public下新建img,js,css文件夹,目录如......
  • Azure for Students 使用指北
    准备一个有AzureforStudents的微软账户。AzureforStudents提供了免费一年的两台B1s实例,两块P664G硬盘,本文将介绍如何利用好这些资源并且不会因为Azure毒瘤......
  • President Obamas Message for Americas Students batch (speech draft)
    Butwhateveryouresolvetodo,Iwantyoutocommittoit.Iwantyoutoreallyworkatit.IknowthatsometimesyougetthatsensefromTVthatyoucanber......
  • [LeetCode] 1700. Number of Students Unable to Eat Lunch
    Theschoolcafeteriaofferscircularandsquaresandwichesatlunchbreak,referredtobynumbers0and1respectively.Allstudentsstandinaqueue.Eachstu......