답안 #543934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
543934 2022-03-31T16:05:53 Z Olympia 어르신 집배원 (BOI14_postmen) C++17
38 / 100
500 ms 16772 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>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O1")
#pragma GCC optimization ("unroll-loops")
 
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].emplace_back(v, i), adj[v].emplace_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.emplace(i, -1);
        bool upd;
        while (!nodes.empty()) {
            int cur = nodes.top().first; int prev = nodes.top().second;
            okay[prev] = false;
            hasVisited[cur] = true;
            upd = false;
            for (pair<int,int> &pr: adj[cur]) {
                int j = pr.first;
                if (pr.second == prev || !okay[pr.second]) {
                    continue;
                }
                okay[pr.second] = false;
                if (hasVisited[j]) {
                    while (!nodes.empty()) {
                        int &x = nodes.top().first; if (x == j) break;
                        hasVisited[x] = false;
                        printf("%d ", x + 1);
                        nodes.pop();
                    }
                    printf("%d\n", j + 1);
                } else {
                    nodes.emplace(j, pr.second);
                }
                upd = true;
                break;
            }
            if (!upd) {
                nodes.pop();
            }
        }
    }
}

Compilation message

postmen.cpp:16: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   16 | #pragma GCC optimization ("O1")
      | 
postmen.cpp:17: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   17 | #pragma GCC optimization ("unroll-loops")
      | 
postmen.cpp: In function 'int main()':
postmen.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d%d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~
postmen.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 8 ms 11988 KB Output is correct
4 Correct 8 ms 12116 KB Output is correct
5 Correct 6 ms 12116 KB Output is correct
6 Correct 8 ms 12116 KB Output is correct
7 Correct 16 ms 12628 KB Output is correct
8 Correct 7 ms 12116 KB Output is correct
9 Correct 56 ms 14552 KB Output is correct
10 Correct 7 ms 12116 KB Output is correct
11 Correct 7 ms 12116 KB Output is correct
12 Correct 42 ms 14820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 7 ms 12116 KB Output is correct
5 Correct 7 ms 12092 KB Output is correct
6 Correct 8 ms 12116 KB Output is correct
7 Correct 13 ms 12604 KB Output is correct
8 Correct 7 ms 12116 KB Output is correct
9 Correct 56 ms 14504 KB Output is correct
10 Correct 10 ms 12116 KB Output is correct
11 Correct 10 ms 12172 KB Output is correct
12 Correct 46 ms 14736 KB Output is correct
13 Correct 54 ms 16716 KB Output is correct
14 Correct 51 ms 15680 KB Output is correct
15 Execution timed out 855 ms 15284 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 7 ms 12060 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 8 ms 12116 KB Output is correct
5 Correct 7 ms 12116 KB Output is correct
6 Correct 8 ms 12236 KB Output is correct
7 Correct 13 ms 12756 KB Output is correct
8 Correct 8 ms 12116 KB Output is correct
9 Correct 58 ms 14548 KB Output is correct
10 Correct 8 ms 12116 KB Output is correct
11 Correct 8 ms 12116 KB Output is correct
12 Correct 45 ms 14856 KB Output is correct
13 Correct 71 ms 16772 KB Output is correct
14 Correct 53 ms 15564 KB Output is correct
15 Execution timed out 834 ms 15360 KB Time limit exceeded
16 Halted 0 ms 0 KB -