이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define endl '\n'
using namespace std;
const int maxn = 1e5 + 3;
int n, m;
multiset <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);
}
}
int depth[maxn];
int par[maxn];
vector <int> cycle;
void dfs(int ver)
{
for (auto i: adj[ver])
{
if (depth[i] == -1)
{
par[i] = ver;
depth[i] = depth[ver] + 1;
dfs(i);
}
else
{
if (depth[i] < depth[ver] - 1)
{
cycle.clear();
int curr = ver;
while (curr != i)
{
cycle.push_back(curr);
curr = par[curr];
}
cycle.push_back(curr);
}
}
}
}
void solve()
{
for (int i = 1; i <= n; i++)
if ((int)adj[i].size() % 2 == 1)
{
cout << "NIE" << endl;
return;
}
vector <vector <int> > ans;
for (;;)
{
int ver = -1;
for (int i = 1; i <= n; i++)
if (!adj[i].empty())
{
ver = i;
break;
}
if (ver == -1)
break;
memset(depth, -1, sizeof(depth));
dfs(ver);
cycle.push_back(cycle[0]);
for (int i = 0; i < (int)cycle.size()-1; i++)
{
adj[cycle[i]].erase(adj[cycle[i]].find(cycle[i+1]));
adj[cycle[i+1]].erase(adj[cycle[i+1]].find(cycle[i]));
}
ans.push_back(cycle);
}
cout << (int)ans.size() << endl;
for (auto i: ans)
{
cout << (int)i.size()-1 << " ";
for (auto j: i)
cout << j << " ";
cout << 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... |