이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100005
#define M ll(1e9 + 7)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef short int si;
int ans[N * 5], cnt, kol[N * 2];
bool mk[N * 5];
vector <pair <int, int> > g[N * 2];
pair <int, int> gr[N * 5];
void dfs(int v, bool f, vector <int> &a, vector <int> &b)
{
while (sz(g[v]))
{
pair <int, int> pt = g[v].back(); g[v].pop_back();
if (mk[pt.S]) continue;
mk[pt.S] = 1;
kol[v]--; kol[pt.F]--;
if (f) a.pb(pt.S); else b.pb(pt.S);
dfs(pt.F, !f, a, b);
break;
}
}
void solve(vector <int> &cur)
{
vector <int> vert; vert.clear();
bool gd = 1;
for (auto it : cur)
{
mk[it] = 0;
int a = gr[it].F, b = gr[it].S;
kol[a]++; kol[b]++;
if (kol[a] == 1) vert.pb(a); else gd = 0;
if (kol[b] == 1) vert.pb(b); else gd = 0;
g[a].pb({b, it});
g[b].pb({a, it});
}
if (gd)
{
cnt++;
for (auto it : cur)
{
int a = gr[it].F, b = gr[it].S;
kol[a]--; kol[b]--;
g[a].clear(); g[b].clear();
ans[it] = cnt;
}
return;
}
vector <int> a, b; a.clear(); b.clear();
for (auto it : vert) if (kol[it] % 2 == 0) dfs(it, 0, a, b);
for (auto it : vert) while (kol[it]) dfs(it, 0, a, b);
solve(a);
solve(b);
}
int main()
{
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector <int> cur; cur.clear();
for (int i = 0; i < k; i++)
{
int a, b;
cin >> a >> b;
gr[i] = {a, n + b};
cur.pb(i);
}
solve(cur);
cout << cnt << '\n';
for (int i = 0; i < k; i++) cout << ans[i] << '\n';
}
# | 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... |