Submission #1310013

#TimeUsernameProblemLanguageResultExecution timeMemory
1310013supersonicman12Senior Postmen (BOI14_postmen)C++17
100 / 100
439 ms84940 KiB
#include <bits/stdc++.h>
using namespace std;

int n, m, ind;
vector<pair<int,int>> G[500005];
int mark[500005],tour[500005];
bool insta[500005],vis[500005];

void hier(int x){
    // cout << x << '\n';
    for (int i = mark[x]; i < G[x].size(); i = mark[x]){
        auto v = G[x][i];
        mark[x] = i+1;
        if (vis[v.second]) continue;
        vis[v.second] = 1;
        hier(v.first);
    }
    if (insta[x]){
        printf("%d", x);
        while (tour[ind] != x){
            printf(" %d", tour[ind]);
            insta[tour[ind]] = 0;
            ind--;
        }
        printf("\n");
    } else {
        insta[x] = 1;
        tour[++ind] = x;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; i++){
        int a, b; 
        scanf("%d %d", &a, &b);
        G[a].emplace_back(b,i);
        G[b].emplace_back(a,i);
    }
    hier(1);
    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]
   35 |     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]
   38 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...