Submission #84230

#TimeUsernameProblemLanguageResultExecution timeMemory
84230nikolapesic2802Untitled (POI11_smi)C++14
100 / 100
1259 ms123604 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int N=1e5+5; vector<int> degree(N); vector<vector<pair<int,int> > > graf(N); vector<int> visited(10*N); vector<vector<int> > sol; stack<int> stk; vector<int> vis(N); vector<int> indx(N); void solve(int tr) { vis[tr]++; stk.push(tr); if(vis[tr]==2) { vector<int> t; t.pb(tr); vis[tr]--; stk.pop(); while(stk.top()!=tr) { t.pb(stk.top()); vis[stk.top()]--; stk.pop(); } t.pb(stk.top()); sol.pb(t); } for(int i=indx[tr];i<graf[tr].size();i++) { indx[tr]++; if(!visited[graf[tr][i].second]) { int p=graf[tr][i].first; visited[graf[tr][i].second]=1; degree[tr]--; degree[p]--; solve(p); return; } } } void fastscan(int &number) { register int c; number = 0; c = getchar(); for (; (c>47 && c<58); c=getchar()) number = number *10 + c - 48; } int main() { int n,m; scanf("%i %i",&n,&m); for(int i=0;i<m;i++) { int a,b,s,t; scanf("%i %i %i %i",&a,&b,&s,&t); if(s!=t) { graf[a].pb({b,i}); graf[b].pb({a,i}); degree[a]++; degree[b]++; } } for(int i=1;i<=n;i++) { if(degree[i]%2==1) { printf("NIE\n"); return 0; } } for(int i=1;i<=n;i++) { while(degree[i]!=0) { while(stk.size()) stk.pop(); solve(i); vis[i]--; } } printf("%d\n",sol.size()); for(auto p:sol) { printf("%d ",p.size()-1); for(auto d:p) { printf("%d ",d); } printf("\n"); } return 0; }

Compilation message (stderr)

smi.cpp: In function 'void solve(int)':
smi.cpp:34:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=indx[tr];i<graf[tr].size();i++)
                        ~^~~~~~~~~~~~~~~~
smi.cpp: In function 'int main()':
smi.cpp:90:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<int> >::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n",sol.size());
                   ~~~~~~~~~~^
smi.cpp:93:32: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
         printf("%d ",p.size()-1);
                      ~~~~~~~~~~^
smi.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %i",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
smi.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i %i %i %i",&a,&b,&s,&t);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...