SCU 4439 Vertex Cover(二分圖最小覆蓋點)題解

題意:每一條邊至少有一個端點要涂顏色,問最少涂幾個點

思路:最小頂點覆蓋:用最少的點,讓每條邊都至少和其中一個點關聯,顯然是道裸最小頂點覆蓋題;

參考:二分圖

代碼:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef unsigned long long ull;
const int maxn = 500 + 10;
const ull seed = 131;
struct Edge{int v, next;
}edge[maxn * maxn * 2];
int head[maxn], match[maxn], vis[maxn], tot;
void addEdge(int u, int v){edge[tot].v = v;edge[tot].next = head[u];head[u] = tot++;
}
bool dfs(int u){for(int i = head[u]; i != -1; i = edge[i].next){int v = edge[i].v;if(!vis[v]){vis[v] = 1;if(match[v] == -1 || dfs(match[v])){match[v] = u;match[u] = v;return true;}}}return false;
}
int solve(int n){int ans = 0;memset(match, -1, sizeof(match));for(int i = 1; i <= n; i++){if(match[i] == -1){memset(vis, 0, sizeof(vis));if(dfs(i)) ans++;}}return ans;
}
int main(){int n, m;while(~scanf("%d%d", &n, &m)){memset(head, -1, sizeof(head));tot = 0;for(int i = 1; i <= m; i++){int u, v;scanf("%d%d", &u, &v);addEdge(u, v);addEdge(v, u);}printf("%d\n", solve(n));}return 0;
}

?

轉載于:https://www.cnblogs.com/KirinSB/p/9898786.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/396231.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/396231.shtml
英文地址,請注明出處:http://en.pswp.cn/news/396231.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

20155229 實驗一《Java開發環境的熟悉》實驗報告

20155229 實驗一《Java開發環境的熟悉》實驗報告 實驗內容 1.使用JDK編譯、運行簡單的Java程序&#xff1b; 2.使用Idea 編輯、編譯、運行、調試Java程序。 實驗步驟 &#xff08;一&#xff09;命令行下Java程序開發 輸入 mkdir 20155229命令建立實驗目錄&#xff0c;用ls查看…

js時間搓化為今天明天_js轉時間戳,時間戳轉js

js轉時間戳轉此時此刻的時間1、var timestamp1 (new Date()).valueOf();valueOf() 方法返回指定對象的原始值2、var timestamp2 new Date().getTime();Date.prototype.getTime()方法的返回值一個數值&#xff0c;表示從1970年1月1 日0時0分0秒(UTC&#xff0c;即協調世界時)距…

PHP代碼20個實用技巧(轉)

這些技巧特別是封裝的&#xff0c;相對路徑的還是挺好的&#xff0c;本身來自微信公眾號&#xff0c;但是我擔心以后刪除&#xff0c;所以在我的博客上備份一下&#xff08;微信公眾號為:菜鳥教程&#xff09; 在這篇文章中我們將看看一些關于PHP開發有用的提示和技巧&#xff…

需求簡報_代碼簡報:NASA將所有研究成果發布為開放數據

需求簡報Here are three stories we published this week that are worth your time:這是我們本周發布的三個值得您關注的故事&#xff1a; With open data, you finally get what you’ve paid for all these years: 4 minute read 有了開放的數據&#xff0c;您終于可以得到…

matlab 16位灰度值轉8位,在matlab中如何將灰度值為24位的轉化為8?

我使用的是Visual c6。0技術內幕里提供的類CDib來操作位圖&#xff0c;最好提供可以兩個獨立的函數來分辨別實現著倆個功能。他們可以作為CDib類的成員函數來使用。類似下面的這個就可以&#xff0c;我用了下面的這個&#xff0c;但是下面這個不好用&#xff0c;處理后的圖象有…

quartz基本使用

創建一個任務調度 Scheduler scheduler StdSchedulerFactory.getDefaultScheduler();//Schedulers can be immediately used to schedule jobs, but they will not start executing any until the .start()scheduler.start();//And then schedule those jobs with triggers th…

em模型補缺失值_基于EM算法數據單變量缺失處理方法研究

龍源期刊網http://www.qikan.com.cn基于EM算法數據單變量缺失處理方法研究作者&#xff1a;黃鉉來源&#xff1a;《科技傳播》2015年第20期摘要數據分析方法大都針對完整數據&#xff0c;而實際上由于一些原因&#xff0c;觀測數據常存在缺失。本文采用EM算法對正態分布下的隨機…

流媒體協議介紹(rtp/rtcp/rtsp/rtmp/mms/hls)

RTP 參考文檔 RFC3550/RFC3551 Real-time Transport Protocol)是用于Internet上針對多媒體數據流的一種傳輸層協議。RTP協議詳細說明了在互聯網上傳遞音頻和視頻的標準數據包格式。RTP協議常用于流媒體系統&#xff08;配合RTCP協議&#xff09;&#xff0c;視…

我從#100DaysOfCode中學到的東西

by E. Wilson由E. Wilson 我從&#xff03;100DaysOfCode中學到的東西 (What I learned from #100DaysOfCode) I made it up to Day 95 before officially ending my #100DaysOfCode challenge. Check out my GitHub repo and see for yourself.在正式結束&#xff03;100Days…

mysql 表ful,你所不知的table is full那些事

當我們要寫入新數據而發生“The table is full”告警錯誤時&#xff0c;先不要著急&#xff0c;按照下面的思路來逐步分析即可&#xff1a;1、查看操作系統以及MySQL的錯誤日志文件確認操作系統的文件系統沒有報錯&#xff0c;并且MySQL的錯誤日志文件中是否有一些最直觀的可見…

Calendar、Date、long類型的時間,三者之間如何轉化

1. Calendar類型轉化為Date類型和long類型 Calendar calendarCalendar.getInstance(); Date datecalendar.getTime(); long timecalendar.getTimeInMillis(); 2.Date類型轉化為Calendar類型和long類型 Date datenew Date(System.currentTimeMillis()100000000); Calendar calen…

sit是什么環境_軟件環境常識 --dev sit uat

DEV環境&#xff1a;DEV顧名思義就是develop&#xff0c;即代碼開發的環境。SIT環境&#xff1a;System Integration Test系統集成測試&#xff0c;開發人員自己測試流程是否走通。UAT環境&#xff1a;User Acceptance Test用戶驗收測試&#xff0c;由專門的測試人員驗證&#…

python基礎數據類型的相關知識點

1、字符串的函數join >>> s "Hello" >>> s1 s.join("你好")#將字符串Hello插入到你好中 >>> s1 你Hello好 >>> s2 "Tanxu".join("你好嗎")#將字符串Tanxu插入到你好嗎中 >>> s2 你Ta…

(轉載)JDOM/XPATH編程指南

JDOM/XPATH編程指南 本文分別介紹了 JDOM 和 XPATH&#xff0c;以及結合兩者進行 XML 編程帶來的好處。 前言 XML是一種優秀的數據打包和數據交換的形式&#xff0c;在當今XML大行于天下&#xff0c;如果沒有聽說過它的大名&#xff0c;那可真是孤陋寡聞了。用XML描述數據的優勢…

谷歌跟oracle_誰贏得了Google VS Oracle? 開發人員贏了。

谷歌跟oracleGoogle has successfully defended itself from a $9 billion lawsuit from Oracle. In doing so, Google’s lawyers have prevented a dangerous precedent that would have given old copyright-hoarding tech companies a way to sue lots of startups and ope…

php上下屬對應關系,由主分類 ID 取出(多個)下級子分類所對應的項,有沒有什么好的辦法?(其實似乎和 PHP 沒什么直接關系?)...

有一個表結構比如&#xff1a;項目&#xff1a;項目ID項目名分類ID...還有一個多級分類結構&#xff1a;分類1 分類1.1 分類1.1.1 分類1.1.1.1 分類1.1.1.2 分類1.2分類2...假定我現在有分類1的序號&#xff0c;現在想通過這個序號取出對應分類1及其子項中的所有項目的列表&…

最長無重復字符子串?

2019獨角獸企業重金招聘Python工程師標準>>> 題目要求&#xff1a; 給定一個字符串S&#xff0c;在該字符串中找到一個最長的沒有重復字符的子串。 轉載于:https://my.oschina.net/datacube/blog/875545

history of Program

1951 – Regional Assembly Language  1952 – Autocode  1954 – IPL (LISP語言的祖先)  1955 – FLOW-MATIC (COBOL語言的祖先)  1957 – FORTRAN (第一個編譯型語言) 1957 – COMTRAN (COBOL語言的祖先)  1958 – LISP  1958 – ALGOL 58  1959 – FACT (COBO…

銷售探討_讓我們一起探討編程資源的領域

銷售探討by Quincy Larson昆西拉爾森(Quincy Larson) 讓我們一起探討編程資源的領域 (Let’s explore the universe of programming resources together) 有很多免費的編程資源。 (There are a lot of free programming resources out there.) Here’s a list of more than a …

利用yii2 gridview實現批量刪除案例

作者&#xff1a;白狼 出處&#xff1a;http://www.manks.top/article/yii2_gridview_deleteall本文版權歸作者&#xff0c;歡迎轉載&#xff0c;但未經作者同意必須保留此段聲明&#xff0c;且在文章頁面明顯位置給出原文連接&#xff0c;否則保留追究法律責任的權利。 今天仍…