이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |