| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1344087 | mxhrvs | Social Engineering (EGOI22_socialengineering) | C++20 | 0 ms | 0 KiB |
#include <vector>
#include <algorithm>
#include "social.h"
using namespace std;
const int MAXN = 200005;
vector<int> adj[MAXN];
int matching[MAXN];
bool visited[MAXN];
bool dfs_match(int u) {
visited[u] = true;
for (int v : adj[u]) {
if (v == 1) continue;
int w = matching[v];
if (w == 0 || (!visited[w] && dfs_match(w))) {
matching[v] = u;
matching[u] = v;
return true;
}
}
return false;
}
void SocialEngineering(int n, int m, vector<pair<int, int>> edges) {
for (int i = 1; i <= n; i++) adj[i].clear(), matching[i] = 0;
for (auto e : edges) {
adj[e.first].push_back(e.second);
adj[e.second].push_back(e.first);
}
for (int i = 2; i <= n; i++) {
if (matching[i] == 0) {
for (int j = 1; j <= n; j++) visited[j] = false;
dfs_match(i);
}
}
while (true) {
int v = GetMove();
if (v == 0) break;
int my_reply = matching[v];
if (my_reply == 0) {
return;
}
MakeMove(my_reply);
}
}