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