Submission #994006

#TimeUsernameProblemLanguageResultExecution timeMemory
994006NoLove어르신 집배원 (BOI14_postmen)C++14
100 / 100
261 ms110400 KiB
/**
 *    author : Lăng Trọng Đạt
 *    created: 07-06-2024 
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
using vi = vector<int>;
#define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
void mx(int& a, int b) { if (b > a) a = b; }
void mi(int& a, int b) { if (b < a) a = b; }
#define si(x) (int)(x.size())
const int INF = 1e18;
const int MOD = 1e9 + 7;
 
const int MAXN = 1e6 + 5;
vector<pii> adj[MAXN];
 
int n, m, a, b;
vector<vi> ans;
bitset<MAXN> in_q, use;
vi path, tour;
void dfs(int v) {
    if (in_q[v]) {
        ans.pb({v});
        in_q[v] = false;
        while (path.back() != v) {
            ans.back().pb({path.back()});
            in_q[path.back()] = 0;
            path.pop_back();
        }
        path.pop_back();
    } 
    while (si(adj[v])) {
        auto[u, id] = adj[v].back();
        adj[v].pop_back();
        if (use[id]) continue;
        use[id] = true;
        if (!in_q[v]) {
            path.pb(v);
            in_q[v] = 1;
        }
        dfs(u);
    }
}
int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("hi.inp", "r")) {
        freopen("hi.txt", "r", stdin);
       freopen("hi.out", "w", stdout);
    } 
 
    cin >> n >> m;
    FOR(i, 1, m) {
        cin >> a >> b;
        adj[a].pb({b, i});
        adj[b].pb({a, i});
    }
    dfs(1);
    int cnt = 0;
    for (auto v : ans) {
        for (int i : v) {
            cout << i << " ";
        }
        cout << "\n";
    }
}

Compilation message (stderr)

postmen.cpp:21:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   21 | const int INF = 1e18;
      |                 ^~~~
postmen.cpp: In function 'void dfs(int)':
postmen.cpp:43:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |         auto[u, id] = adj[v].back();
      |             ^
postmen.cpp: In function 'int32_t main()':
postmen.cpp:17:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   17 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
postmen.cpp:62:5: note: in expansion of macro 'FOR'
   62 |     FOR(i, 1, m) {
      |     ^~~
postmen.cpp:68:9: warning: unused variable 'cnt' [-Wunused-variable]
   68 |     int cnt = 0;
      |         ^~~
postmen.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen("hi.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
postmen.cpp:58:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |        freopen("hi.out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...