| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1358754 | yogesh_sane | Social Engineering (EGOI22_socialengineering) | C++20 | 0 ms | 0 KiB |
#include <iostream>
#include <vector>
using namespace std;
vector<bool> visited, challenger;
vector<vector<int>> paths, adj;
vector<int> friends;
vector<bool> challenged_by;
int last;
void MakeMove(int f);
int GetMove();
int dfs(int s){
visited[s] = true;
vector<int> unmatched;
if(challenger[s])
unmatched.push_back(s);
for(auto u : adj[s]){
if(!visited[u]){
int uc = dfs(u);
if(uc){
paths[uc].push_back(s);
unmatched.push_back(uc);
}
}
}
while(unmatched.size() >= 2){
int a = unmatched.back();
unmatched.pop_back();
int b = unmatched.back();
unmatched.pop_back();
for(int f = paths[b].size()-2; f >= 0; f--)
paths[a].push_back(paths[b][f]);
if(paths[a].size() == 0 || paths[a].back() != b)
paths[a].push_back(b);
paths[b].clear();
for(int f = paths[a].size()-2; f >= 0; f--)
paths[b].push_back(paths[a][f]);
if(paths[b].size() == 0 || paths[b].back() != a)
paths[b].push_back(a);
}
return unmatched.size() > 0 ? unmatched[0] : 0;
}
void SocialEngineering(int n, int m, vector<pair<int, int>> edges){
adj = vector<vector<int>>(n+1);
challenger = vector<bool>(n+1);
for(int i = 0; i < m; i++){
int u = edges[i].first, v = edges[i].second;
adj[u].push_back(v);
adj[v].push_back(u);
if(min(u,v) == 1)
challenger[max(u,v)] = true;
}
visited = vector<bool>(n+1);
paths = vector<vector<int>>(n+1);
visited[1] = true;
bool win = true;
for(int i : adj[1]){
if(!visited[i]){
int uc = dfs(i);
if(uc){
win = false;
break;
}
}
}
if(!win)
return;
int f = GetMove();
while(f){
for(auto c : paths[f])
MakeMove(c);
MakeMove(1);
f = GetMove();
}
return;
}
