Submission #610574

#TimeUsernameProblemLanguageResultExecution timeMemory
6105741binUntitled (POI11_smi)C++14
100 / 100
930 ms143980 KiB
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() typedef long long ll; const int NMAX = 1e6 + 5; int n, m, a, b, s, p, w[NMAX], chk[NMAX], vis[NMAX]; vector<pair<int, int>> adj[NMAX]; vector<int> t; vector<vector<int>> ans; stack<int> st; void dfs(int x){ for(auto& i = w[x]; i < adj[x].size(); i++){ auto& [nx, e] = adj[x][i]; if(chk[e]) continue; chk[e] = 1; dfs(nx); } t.emplace_back(x); return; } int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 0; i < m; i++){ cin >> a >> b >> s >> p; if(s ^ p) { adj[a].emplace_back(b, i); adj[b].emplace_back(a, i); } } for(int i = 1; i <= n; i++) if(adj[i].size() & 1){ cout << "NIE"; return 0; } for(int i = 1; i <= n; i++) if(w[i] < adj[i].size()) dfs(i); for(int& x : t) { if(vis[x]){ vector<int> v(1, x); while(1){ int cur = st.top(); v.emplace_back(cur); if(cur == x) break; st.pop(); vis[cur] = 0; } ans.emplace_back(v); } else st.emplace(x), vis[x] = 1; } cout << ans.size() << '\n'; for(auto& t : ans){ cout << t.size()- 1 << ' '; for(int x : t) cout << x << ' '; cout << '\n'; } return 0; }

Compilation message (stderr)

smi.cpp: In function 'void dfs(int)':
smi.cpp:15:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(auto& i = w[x]; i < adj[x].size(); i++){
      |                         ~~^~~~~~~~~~~~~~~
smi.cpp:16:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   16 |         auto& [nx, e] = adj[x][i];
      |               ^
smi.cpp: In function 'int main()':
smi.cpp:42:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         if(w[i] < adj[i].size()) dfs(i);
      |            ~~~~~^~~~~~~~~~~~~~~
#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...