답안 #733936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733936 2023-05-01T12:13:19 Z DAleksa 어르신 집배원 (BOI14_postmen) C++17
0 / 100
7 ms 12196 KB
#include <bits/stdc++.h>

using namespace std;

struct edge {
    int v;
    int id;
};

const int N = 5e5 + 10;
vector<edge> g[N];
int n, m;
vector<int> eulerian_cycle;
bool mark[N];
int cnt[N];
int id = 0;

void find_eulerian_cycle(int u) {
    for(edge v : g[u]) {
        if(mark[v.id]) continue;
        mark[v.id] = true;
        find_eulerian_cycle(v.v);
        eulerian_cycle.push_back(v.v);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back({v, id});
        g[v].push_back({u, id++});
    }
    int start = 1;
    for(int i = 2; i <= n; i++) {
        if(g[i].size() > 2) {
            start = i;
            break;
        }
    }
    find_eulerian_cycle(start);
    eulerian_cycle.push_back(start);
    vector<vector<int>> ans;
    stack<int> stk;
    stk.push(eulerian_cycle[0]);
    for(int i = 1; i <= n; i++) cnt[i] = 0;
    cnt[eulerian_cycle[0]]++;
    for(int i = 0; i < eulerian_cycle.size(); i++) cout << eulerian_cycle[i] << " ";
    cout << "\n";
    for(int i = 1; i < eulerian_cycle.size(); i++) {
        if(cnt[eulerian_cycle[i]]) {
            ans.push_back({});
            ans[ans.size() - 1].push_back(eulerian_cycle[i]);
            while(stk.top() != eulerian_cycle[i]) {
                ans[ans.size() - 1].push_back(stk.top());
                cnt[stk.top()]--;
                stk.pop();
            }
        } else {
            cnt[eulerian_cycle[i]]++;
            stk.push(eulerian_cycle[i]);
        }
    }
    for(vector<int> i : ans) {
        for(int j : i) cout << j << " ";
        cout << "\n";
    }
    return 0;
}

Compilation message

postmen.cpp: In function 'int main()':
postmen.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i = 0; i < eulerian_cycle.size(); i++) cout << eulerian_cycle[i] << " ";
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~
postmen.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i = 1; i < eulerian_cycle.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 11988 KB Same junction appears twice in a route
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 12196 KB Same junction appears twice in a route
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 11988 KB Same junction appears twice in a route
2 Halted 0 ms 0 KB -