Cod sursa(job #1974162)

Utilizator brczBereczki Norbert Cristian brcz Data 26 aprilie 2017 23:33:58
Problema Cuplaj maxim in graf bipartit Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.92 kb
#include<bits/stdc++.h>

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
#define bg begin
#define nd end
using namespace std;

const int maxn = 100003;
const int maxk = 1003;

vector<int> possibleDays[maxk];
bool viz[maxk];
int days[maxk];
int ans[maxk];
bool vizDay[maxk];

int n,k,m,e,x,y;
string subreddit[maxk];
int subscribers[maxk];

int main(){

	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	#endif

	ios_base::sync_with_stdio(false);

	cin >> n >> m >> e ;

	int x;

	for(int i=0;i<e;i++){
		cin >> x >> y;
		possibleDays[x].pb(y);
		days[y]++;
	}

	// for(int i=1;i<=n;i++){
		// cin >> subreddit[i];
		// for(int j=1;j<=k;j++){
			// cin >> subscribers[j];
			// if(j >= 3 && subscribers[j] > subscribers[j-1] && subscribers[j-1] > subscribers[j-2]){
				// possibleDays[i].pb(j);
				// days[j]++;
			// }
		// }
	// }


	bool ok = true;
	while(ok){
		ok = false;
		int minime = (int)(1e6);
		int posRed = -1;


		for(int i=1;i<=n;i++){
			if(!viz[i] && minime > possibleDays[i].sz()){
				minime = possibleDays[i].sz();
				posRed = i;
			}
		}
		int currDayAns = -1;
		if(posRed != -1){
			ok = true;
			viz[posRed] = true;

			int minDay = (int)(1e6);
			for(int i=0;i<possibleDays[posRed].sz();i++){
				if(minDay > days[possibleDays[posRed][i]]){
					minDay = days[possibleDays[posRed][i]];
					currDayAns = possibleDays[posRed][i];
				}
			}
			//Put solution
			ans[currDayAns] = posRed;

			//Cleanup
			for(int i=0;i<possibleDays[posRed].sz();i++){
				days[possibleDays[posRed][i]]--;
			}

			for(int i=1;i<=n;i++){
				for(vector<int>::iterator j=possibleDays[i].begin();j!=possibleDays[i].end();j++){
					if(*j == currDayAns){
						possibleDays[i].erase(j);
						break;
					}
				}
			}

		}

	}


	for(int i=1;i<=m;i++){
		if(ans[i] == 0){
		}
		else{
			cout << ans[i] << ' ' << i << '\n';
		}
	}


	return 0;
}