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 <bits/stdc++.h>
#pragma GCC optimize("O3")
#define endl '\n'
using namespace std;
const int maxn = 1e5 + 3;
int n, m;
set <int> adj[maxn];
void read()
{
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int a, b, s, t;
cin >> a >> b >> s >> t;
if (s == t)
continue;
adj[a].insert(b);
adj[b].insert(a);
}
}
vector <vector <int> > ans;
bool used[maxn];
void solve()
{
for (int i = 1; i <= n; i++)
if ((int)adj[i].size() % 2 == 1)
{
cout << "NIE" << endl;
return;
}
for (;;)
{
for (int i = 1; i <= n; i++)
used[i] = false;
bool is = false;
for (int i = 1; i <= n; i++)
if (!adj[i].empty())
{
vector <int> order;
order.push_back(i);
used[i] = true;
for (;;)
{
int ver = order.back();
auto it = adj[ver].begin();
if ((int)order.size() != 1 && *it == order[(int)order.size()-2])
it++;
if (used[*it])
{
vector <int> cycle;
cycle.push_back(*it);
for (int i = (int)order.size()-1; i >= 0 && order[i] != *it; i--)
cycle.push_back(order[i]);
for (int i = 0; i < (int)cycle.size()-1; i++)
{
adj[cycle[i]].erase(cycle[i+1]);
adj[cycle[i+1]].erase(cycle[i]);
}
adj[cycle[0]].erase(cycle.back());
adj[cycle.back()].erase(cycle[0]);
ans.push_back(cycle);
break;
}
order.push_back(*it);
}
is = true;
break;
}
if (!is)
break;
}
cout << (int)ans.size() << endl;
for (auto i: ans)
{
cout << (int)i.size() << " ";
for (auto j: i)
cout << j << " ";
cout << i[0] << endl;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
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... |