Title Description
lxhgww recently fell in love with a game, in the game, he has a lot of equipment, each equipment has two properties, the values of these properties with the number between [1,10000] representation. When he uses some equipment, he can only use one attribute of the equipment. And can only be used at most once for each equipment. Game to the last, lxhgww met the ultimate boss, the ultimate boss is very strange, property values used to attack his equipment must continuously increasing attack from start 1, in order to harm the boss. That is the beginning of time, lxhgww can only use one attack boss property and equipment value of 1, and then only use the value of a property, equipped with attack boss 2, and then only use the value of a property and equipment 3 attack boss ...... and so on. Now he wants to know lxhgww up to attack a boss How many times?
Input Format
The first line of the input N is an integer, N denotes lxhgww kinds of equipment has N rows Next, N is the description of these kinds of equipment, each row two numbers indicate two attribute values of the i-th equipment
Output Format
Output line, comprising a number representing the number of continuous attacks lxhgww up.
Sample input and output
3 1 2 3 2 4 5
2
Description / Tips
Limitation
For 30% of the data, to ensure that N <= 1000
To 100% of the data, to ensure that N <= 1000000
Source: SCOI 2010
So the questions should be very simple matter
That left the property on the number on the right to do the most matches
Still very good understanding da ~ ~ ~
#include<bits/stdc++.h> #define maxn 1000005 using namespace std; vector<int> v[maxn]; int vis[maxn],hav[maxn];int tim; bool Dfs(int rt) { for(int i=0;i<v[rt].size();i++) { int to=v[rt][i]; if(vis[to]!=tim) { vis[to]=tim; if(!hav[to]||Dfs(hav[to])) { hav[to]=rt; return true; } } } return false; } int main () { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { int a,b;scanf("%d%d",&a,&b); v[a].push_back(i);v[b].push_back(i); } int ans=0; for(int i=1;i<=n;i++) { tim++; if(Dfs(i)) ans++; else break; } printf("%d",ans); return 0; }