제출 #543908

#제출 시각아이디문제언어결과실행 시간메모리
543908OlympiaSenior Postmen (BOI14_postmen)C++17
0 / 100
2 ms596 KiB
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#include <cmath>
#include <map>
#include <random>
#include <cassert>
#include <ctime>
#include <stack>
#include <cstdlib>
#include <queue>
#include <limits.h>

using namespace std;

vector<vector<pair<int,int>>> adj;
vector<bool> hasVisited;

int main() {
    //freopen("balancing.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M;
    scanf("%d%d", &N, &M);
    adj.resize(N); hasVisited.assign(N, false);
    vector<bool> okay(M);
    for (int i = 0; i < M; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        adj[u].push_back({v, i}), adj[v].push_back({u, i});
    }
    okay.assign(M, true);
    stack<pair<int,int>> nodes;
    for (int i = 0; i < N; i++) {
        nodes.push({i, -1});
        while (!nodes.empty()) {
            //nodes.
            int cur = nodes.top().first;
            int prev = nodes.top().second;
            hasVisited[cur] = true;
            bool upd = false;
            for (pair<int,int> pr: adj[cur]) {
                int j = pr.first;
                if (pr.second == prev) {
                    continue;
                }
                if (!okay[pr.second]) {
                    continue;
                }
                if (hasVisited[j]) {
                    while (!nodes.empty() && nodes.top().first != j) {
                        hasVisited[nodes.top().first] = false;
                        cout << nodes.top().first + 1 << ' ';
                        okay[nodes.top().second] = false;
                        nodes.pop();
                    }
                    okay[pr.second] = false;
                    cout << j + 1 << ' ';
                    cout << '\n';
                } else {
                    nodes.push({j, pr.second});
                }
                upd = true;
                break;
            }
            if (!upd) {
                nodes.pop();
            }
        }
    }
}

컴파일 시 표준 에러 (stderr) 메시지

postmen.cpp: In function 'int main()':
postmen.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d%d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~
postmen.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...