This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// g++ -std=c++14
/*
Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.
- Tooru Oikawa.
*/
#include<bits/stdc++.h>
typedef long long ll;
typedef long double lld;
using namespace std;
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define pii pair<int, int>
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template <typename T>
ostream &operator<<(ostream &out, set<T> const &v) {
for (auto i = v.begin(); i != v.end(); i++)
out << (*i) << ' ';
return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, map<T, V> const &v) {
for (auto i = v.begin(); i != v.end(); i++)
out << "\n" << (i->first) << ":" << (i->second);
return out;
}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
#define int ll
//1 indexed Hopcroft-Karp Matching in O(E sqrtV)
struct Hopcroft_Karp
{
static const int inf = 1e9;
int n;
vector<int> matchL, matchR, dist;
vector<vector<int> > g;
int mark_node;
int matching;
Hopcroft_Karp(int n) :
n(n), matchL(n+1), matchR(n+1), dist(n+1), g(n+1) {
mark_node = -1;
matching = 0;
}
void addEdge(int u, int v)
{
g[u].push_back(v);
}
bool bfs()
{
queue<int> q;
for(int u=1;u<=n;u++)
{
if(!matchL[u] && u != mark_node)
{
dist[u]=0;
q.push(u);
}
else
dist[u]=inf;
}
dist[0]=inf;
while(!q.empty())
{
int u=q.front();
// tr(u);
q.pop();
for(auto v:g[u])
{
if(dist[matchR[v]] == inf && matchR[v] != mark_node)
{
dist[matchR[v]] = dist[u] + 1;
q.push(matchR[v]);
// tr(matchR[v]);
}
}
}
return (dist[0]!=inf);
}
bool dfs(int u)
{
if(!u)
return true;
for(auto v:g[u])
{
if(dist[matchR[v]] == dist[u]+1 &&dfs(matchR[v]))
{
matchL[u]=v;
matchR[v]=u;
return true;
}
}
dist[u]=inf;
return false;
}
int max_matching()
{
matching=0;
while(bfs())
{
for(int u=1;u<=n;u++)
{
if(!matchL[u])
if(dfs(u))
matching++;
}
}
return matching;
}
int get(int v) {
// tr(v);
if (matchL[v] == 0) return matching;
else {
int t = matchL[v];
mark_node = v;
matchR[t] = 0;
matching--;
int yes = 0;
if (bfs()) {
yes = 1;
}
matchL[v] = t;
matchR[t] = v;
int ans = matching + yes;
matching++;
return ans;
}
}
};
int solve() {
int n, m;
cin >> n >> m;
Hopcroft_Karp h(2 * n);
for (int i = 1; i <= m; i++) {
int v, u;
cin >> v >> u;
h.addEdge(v, u + n);
}
int maxm = h.max_matching();
// tr(maxm, h.matchR, h.matchL);
for (int i = 1; i <= n; i++) {
int lol = h.get(i);
if (lol == maxm) {
cout << "Mirko" << endl;
} else {
cout << "Slavko" << endl;
}
}
return 0;
}
int32_t main(){ _
int t;
// cin >> t;
t = 1;
while (t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |