Submission #922278

# Submission time Handle Problem Language Result Execution time Memory
922278 2024-02-05T11:06:54 Z AndrijaM Senior Postmen (BOI14_postmen) C++17
0 / 100
4 ms 12636 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn=5e5+10;
int di[4]={1,-1,0,0};
int dj[4]={0,0,-1,1};

int n,m;
bool vis[maxn];
vector<pair<int,int>>g[maxn];
vector<int>path;

void dfs(int node)
{
    while(!g[node].empty())
    {
        auto ax=g[node].back();
        g[node].pop_back();
        if(vis[ax.second])continue;
        vis[ax.second]=1;
        dfs(ax.first);
    }
    path.push_back(node);
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin>>n>>m;
    memset(vis,0,sizeof vis);
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        x--;y--;
        g[x].push_back({y,i});
        g[y].push_back({x,i});
    }
    dfs(0);
    map<int,int>ma;
    vector<int>a;
    for(auto ax:path)
    {
        a.push_back(ax);
        ma[ax]++;
        if(ma[ax]==2)
        {
            cout<<ax+1<< " ";
            a.pop_back();
            while(a.back()!=ax)
            {
                cout<<a.back()+1<<" ";
                ma[a.back()]--;
                a.pop_back();
            }
            cout<<ax+1<<endl;
            ma[ax]=1;
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 12636 KB Same junction appears twice in a route
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 12636 KB Same junction appears twice in a route
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 12636 KB Same junction appears twice in a route
2 Halted 0 ms 0 KB -