Submission #543915

# Submission time Handle Problem Language Result Execution time Memory
543915 2022-03-31T15:24:13 Z Olympia Senior Postmen (BOI14_postmen) C++17
0 / 100
6 ms 11988 KB
#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 <cstdio>
#include <limits.h>

using namespace std;

vector<pair<int,int>> adj[(int)5e5];
bool hasVisited[(int)5e5];
bool okay[(int)5e5];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M;
    scanf("%d%d", &N, &M);
    for (int i = 0; i < M; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        u--, v--;
        adj[u].push_back({v, i}), adj[v].push_back({u, i});
    }
    for (int i = 0; i < M; i++) {
        okay[i] = true;
    }
    stack<pair<int,int>> nodes;
    for (int i = 0; i < N; i++) {
        nodes.push({i, -1});
        while (!nodes.empty()) {
            int cur = nodes.top().first;
            int prev = nodes.top().second;
            okay[prev] = false;
            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;
                        printf("%d ", nodes.top().first + 1);
                        //okay[nodes.top().second] = false;
                        nodes.pop();
                    }
                    //okay[pr.second] = false;
                    printf("%d\n", j + 1);
                } else {
                    nodes.push({j, pr.second});
                }
                upd = true;
                break;
            }
            if (!upd) {
                nodes.pop();
            }
        }
    }
}

Compilation message

postmen.cpp: In function 'int main()':
postmen.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d%d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~
postmen.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Incorrect 6 ms 11988 KB Edge does not exist or used 3, 7
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Incorrect 6 ms 11988 KB Edge does not exist or used 3, 7
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Incorrect 6 ms 11988 KB Edge does not exist or used 3, 7
3 Halted 0 ms 0 KB -