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];
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);
ss << res.size()-1;
for (int x : res)
ss << " " << x+1;
ss << endl;
if (res[0] != res.back()) {
cout << "NIE" << endl;
return 0;
}
cnt++;
}
}
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... |