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>
using namespace std;
const int N = 1e5+7, M = 1e6+7;
int n, m;
vector<int> adj[N];
int a[M], b[M];
int freq[N];
bool used[M];
vector<int> hh(int s) {
vector<int> st;
st.push_back(s);
vector<int> ans;
while (st.size()) {
int v = st.back();
if (!adj[v].size()) {
ans.push_back(v);
st.pop_back();
}
while (adj[v].size()) {
int e = adj[v].back();
adj[v].pop_back();
int w = a[e]^b[e]^v;
if (!used[e]) {
used[e] = 1;
st.push_back(w);
break;
}
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for (int i = 0; i < m; i++) {
int s, t;
cin>>a[i]>>b[i]>>s>>t;
if (s ^ t) {
adj[--a[i]].push_back(i);
adj[--b[i]].push_back(i);
}
}
int cnt = 0;
stringstream ss;
for (int i = 0; i < n; i++) {
if (adj[i].size()) {
vector<int> res = hh(i);
vector<int> ans;
for (int x : res) {
ans.push_back(x);
if (++freq[x] == 2) {
vector<int> q;
while (freq[x]) {
q.push_back(ans.back());
freq[ans.back()]--;
ans.pop_back();
}
ss << q.size()-1;
for (int y : q)
ss << " " << y+1;
ss << endl;
ans.push_back(x);
freq[x]++;
cnt++;
}
}
if (res[0] != res.back()) {
cout << "NIE" << endl;
return 0;
}
}
}
cout << cnt << endl;
cout << ss.str();
return 0;
}
# | 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... |