Submission #88746

#TimeUsernameProblemLanguageResultExecution timeMemory
88746popovicirobertSenior Postmen (BOI14_postmen)C++14
55 / 100
614 ms55700 KiB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

const int MAXN = (int) 5e5;

vector <int> g[MAXN + 1];
pair <int, int> edges[MAXN + 1];
bool vis[MAXN + 1], vis1[MAXN + 1];
vector <int> ord;

void dfs(int nod) {
    while(g[nod].size()) {
        auto it = g[nod].back();
        g[nod].pop_back();
        if(vis[it] == 0) {
            vis[it] = 1;
            dfs(edges[it].first ^ edges[it].second ^ nod);
        }
    }
    ord.push_back(nod);
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n, m;
    //ios::sync_with_stdio(false);
    //cin.tie(0), cout.tie(0);
    scanf("%d%d" ,&n,&m);
    for(i = 1; i <= m; i++) {
        int x, y;
        scanf("%d%d" ,&x,&y);
        edges[i] = {x, y};
        g[x].push_back(i);
        g[y].push_back(i);
    }
    dfs(1);
    int sz = ord.size();
    vector <int> stk;
    for(i = 0; i < sz; i++) {
        if(vis1[ord[i]] == 0) {
            vis1[ord[i]] = 1;
            stk.push_back(ord[i]);
        }
        else {
            while(stk.back() != ord[i]) {
                cout << stk.back() << " ";
                vis1[stk.back()] = 0;
                stk.pop_back();
            }
            cout << ord[i] << "\n";
        }
    }
    //cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d" ,&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
postmen.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d" ,&x,&y);
         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...