Submission #980745

#TimeUsernameProblemLanguageResultExecution timeMemory
980745fv3Senior Postmen (BOI14_postmen)C++14
55 / 100
370 ms262144 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<queue<int>> adj; vector<unordered_set<int>> c; vector<int> ep; void euler(int index, int last) { c[last].insert(index); while (!adj[index].empty()) { int node = adj[index].front(); adj[index].pop(); if (!c[node].count(index)) euler(node, index); } ep.push_back(index); } int main() { int N, M; cin >> N >> M; adj.resize(N); c.resize(N); for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; a--; b--; adj[a].push(b); adj[b].push(a); } euler(0, 0); for (auto v : ep) cerr << v+1 << ' '; cerr<<'\n'; vector<int> occourence(N, -1); vector<int> linkedList(ep.size(), -1); iota(linkedList.begin(), linkedList.end(), 1); for (int i = 0; i < ep.size(); i++) { int value = ep[i]; if (occourence[value] != -1) { int j = linkedList[occourence[value]]; linkedList[occourence[value]] = i + 1; for (; j < i; j = linkedList[j]) { cout << ep[j] + 1 << ' '; occourence[ep[j]] = -1; } cout << ep[i] + 1 << '\n'; continue; } occourence[value] = i; } return 0; } /* 5 6 1 2 1 3 1 4 1 5 2 3 4 5 */

Compilation message (stderr)

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