# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
367821 | mathking1021 | Senior Postmen (BOI14_postmen) | C++17 | 803 ms | 107904 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef int ll;
ll n, m;
vector<ll> ve[500005];
vector<bool> ve2[500005];
ll cnt;
ll x[500005];
bool v[500005];
bool vvvv = false;
ll g(ll p, ll q)
{
return (lower_bound(ve[p].begin(), ve[p].end(), q) - ve[p].begin());
}
ll f(ll p)
{
v[p] = true;
for(ll i = 0; i < ve[p].size(); i++)
{
if(ve2[p][i]) continue;
ve2[p][i] = true;
ve2[ve[p][i]][g(ve[p][i], p)] = true;
x[p]--, x[ve[p][i]]--;
if(v[ve[p][i]])
{
if(vvvv) puts("");
vvvv = true;
printf("%d %d ", ve[p][i], p);
v[p] = false;
return ve[p][i];
}
ll t = f(ve[p][i]);
if(t == p)
{
continue;
}
else
{
printf("%d ", p);
v[p] = false;
return t;
}
}
v[p] = false;
return -1;
}
int main()
{
scanf("%d%d", &n, &m);
for(ll i = 0; i < m; i++)
{
ll t1, t2;
scanf("%d%d", &t1, &t2);
ve[t1].push_back(t2);
ve[t2].push_back(t1);
ve2[t1].push_back(false);
ve2[t2].push_back(false);
x[t1]++, x[t2]++;
}
for(ll i = 1; i <= n; i++) sort(ve[i].begin(), ve[i].end());
for(ll i = 1; i <= n; i++)
{
while(x[i] > 0) f(i);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |