제출 #167938

#제출 시각아이디문제언어결과실행 시간메모리
167938Thuleanx무제 (POI11_smi)C++14
10 / 100
951 ms42876 KiB
#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]++; } } if (ans.size() > 1) { cout << "NIE" << endl; return 0; } cnt++; } } cout << cnt << endl; cout << ss.str(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...