#include <bits/stdc++.h>
using namespace std;
vector<int> v;int in[100001],vis[100001];
vector<int> adj[100001];int cnt = 0;
map<pair<int,int>,int> mp;
void dfs(int i){
vis[i] = 1;
while(in[i]){
if(mp[{i,adj[i][in[i]-1]}]==0){
mp[{i,adj[i][in[i]-1]}] = 1;
mp[{adj[i][in[i]-1],i}] = 1;
dfs(adj[i][--in[i]]);
}else in[i]--;
}
v.push_back(i);
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
for(int i = 0;i<m;i++){
int a,b,c,d;
cin>>a>>b>>c>>d;
if(c==d)continue;
adj[a].push_back(b);
adj[b].push_back(a);
in[a]++;in[b]++;
}
for(int i = 1;i<=n;i++){
if(in[i]%2){
cout<<"NIE\n";
return 0;
}
}
vector<vector<int>> all;
int de[n+1] = {0};
for(int i = 1;i<=n;i++){
if(!vis[i]){
v.clear();
dfs(i);
vector<int>tmp;
reverse(v.begin(),v.end());
for(int j = 0;j<v.size();j++){
tmp.push_back(v[j]);
if(de[v[j]]==i){
vector<int>hla;
int cn = 0;
while(cn<2){
cn+=(tmp.back()==v[j]);
hla.push_back(tmp.back());tmp.pop_back();
}
reverse(hla.begin(),hla.end());
all.push_back(hla);
tmp.push_back(v[j]);
}
de[v[j]]=i;
}
}
}
cout<<all.size()<<"\n";
for(auto i:all){cout<<i.size()-1<<" ";for(auto j:i)cout<<j<<" ";cout<<endl;}
return 0;
}
//1221
Compilation message
smi.cpp: In function 'int main()':
smi.cpp:44:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int j = 0;j<v.size();j++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
7120 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
11 ms |
9544 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
8484 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
21 ms |
14232 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
217 ms |
89468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1469 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1931 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2411 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |