Submission #745371

#TimeUsernameProblemLanguageResultExecution timeMemory
745371Markomafko972Senior Postmen (BOI14_postmen)C++14
100 / 100
379 ms73004 KiB
#include <bits/stdc++.h> #define X first #define Y second #define pb push_back #define pii pair<int, int> typedef long long ll; using namespace std; const int MOD = 1e9 + 7; const ll INF = 1e18; const int OFF = (1 << 20); int n, m, a, b; vector<pii> s[500005]; vector<int> v; vector<int> ost; int bio[500005]; vector<int> rj[500005]; int sol = 0; void dfs(int x) { while (s[x].size() > 0) { while (s[x].size() > 0 && s[x].back().Y == -1) s[x].pop_back(); if (s[x].size() == 0) break; pii sus = s[x].back(); s[sus.X][sus.Y].Y = -1; s[x].pop_back(); dfs(sus.X); } v.push_back(x); } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a >> b; s[a].push_back({b, (int)s[b].size()}); s[b].push_back({a, (int)s[a].size()-1}); } dfs(1); reverse(v.begin(), v.end()); int kol = 0; for (int i = 0; i < v.size(); i++) { if (bio[v[i]]) { rj[sol].push_back(v[i]); while (ost.back() != v[i]) { rj[sol].push_back(ost.back()); bio[ost.back()]--; ost.pop_back(); } kol += rj[sol].size(); sol++; } else { bio[v[i]] = 1; ost.push_back(v[i]); } } if (kol != m) assert(0); for (int i = 0; i < sol; i++) { for (int j = 0; j < rj[i].size(); j++) cout << rj[i][j] << " "; cout << "\n"; } return 0; }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
postmen.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for (int j = 0; j < rj[i].size(); j++) cout << rj[i][j] << " ";
      |                   ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...