Submission #1084312

# Submission time Handle Problem Language Result Execution time Memory
1084312 2024-09-05T20:23:43 Z teesla Senior Postmen (BOI14_postmen) C++17
100 / 100
293 ms 83028 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;

vector<vector<ii>> adj;
stack<int> res;
vector<int> vis, edge;

int dfs(int x){

    vis[x] = 1;

    while(!adj[x].empty()){
        auto [viz, idx] = adj[x].back();
        adj[x].pop_back();
        if(edge[idx]) continue;
        edge[idx] = 1;

        if(vis[viz]){
            res.push(x);
            vis[x] = 0;
            return viz;
        }
        int k = dfs(viz);
        if(k == x){
            res.push(x);
            while(!res.empty()){
                if(res.top() != x) cout << ' ';
                cout << res.top();
                res.pop();
            }
            cout <<"\n";
        }
        else{
            res.push(x);
            vis[x] = 0;
            return k;
        }
    }

    vis[x] = 0;
    return 0;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m; cin >> n >> m;
    
    adj.resize(n+2);
    vis.assign(n+2, 0);
    edge.assign(m+2,0);

    for(int i=0; i<m; i++){
        int a,b; cin >> a >> b;
        adj[a].push_back({b,i});
        adj[b].push_back({a,i});
    }

    for(int i=1; i<=n; i++){
        if(!adj[i].empty()) dfs(i);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 3 ms 856 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 18 ms 3240 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 20 ms 3488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 3 ms 856 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 18 ms 3164 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 21 ms 3408 KB Output is correct
13 Correct 36 ms 15444 KB Output is correct
14 Correct 35 ms 6484 KB Output is correct
15 Correct 27 ms 5584 KB Output is correct
16 Correct 34 ms 15440 KB Output is correct
17 Correct 31 ms 5968 KB Output is correct
18 Correct 33 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 18 ms 3164 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 21 ms 3420 KB Output is correct
13 Correct 38 ms 15440 KB Output is correct
14 Correct 29 ms 6232 KB Output is correct
15 Correct 26 ms 5664 KB Output is correct
16 Correct 46 ms 15348 KB Output is correct
17 Correct 38 ms 5948 KB Output is correct
18 Correct 31 ms 8276 KB Output is correct
19 Correct 282 ms 76116 KB Output is correct
20 Correct 207 ms 30288 KB Output is correct
21 Correct 189 ms 26956 KB Output is correct
22 Correct 293 ms 83028 KB Output is correct
23 Correct 110 ms 16960 KB Output is correct
24 Correct 228 ms 34672 KB Output is correct
25 Correct 232 ms 47188 KB Output is correct