답안 #490434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
490434 2021-11-27T13:58:39 Z MohamedAliSaidane 어르신 집배원 (BOI14_postmen) C++14
0 / 100
5 ms 5364 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define pb push_back
#define popb pop_back
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
int nx[4] = {1,-1,0,0}, ny[4] = {0,0,1,-1};

const int MAX_N = 1e5 + 4;
int n, m;
set<int> adj[MAX_N];
vpi edges;
vector<vi> ans;
bool seen[MAX_N];
int paths = 0;
bool works(int u, int dest, int par)
{
    seen[u] = 1;
    for(auto e: adj[u])
    {
        if(e == par)
            continue;
        if(e == dest)
        {
            edges.pb({u,e});
            seen[u] = 0;
            return true;
        }
        if(seen[e])
            continue;
        if(works(e,dest,u))
        {
            edges.pb({u,e});
            seen[u] = 0;
            return true;
        }
    }
    seen[u] = 0;
    return false;
}
void solve()
{
    cin >> n >> m;
    for(int i=  1; i <=m; i ++)
    {
        int a, b;
        cin >>  a >> b;
        adj[a].insert(b);
        adj[b].insert(a);
    }
    ans.resize(n);
    for(int i=  1;i  <= n; i ++)
    {
        if(works(i,i,0))
        {
            reverse(all(edges));
            for(auto e: edges)
            {
                //cout << i << " cbon  "<< e.ff  << endl;
                ans[paths].pb(e.ff);
                adj[e.ff].erase(e.ss);
                adj[e.ss].erase(e.ff);
            }
            edges.clear();
            paths ++;
        }
    }
    for(auto vec: ans)
    {
        for(auto e: vec)
            cout << e << ' ';
        cout << '\n';
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 2 ms 4896 KB Output is correct
4 Correct 5 ms 5324 KB Output is correct
5 Incorrect 3 ms 5024 KB Some edges were not used
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5016 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 5 ms 5364 KB Output is correct
5 Incorrect 3 ms 5020 KB Some edges were not used
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 5324 KB Output is correct
5 Incorrect 3 ms 5068 KB Some edges were not used
6 Halted 0 ms 0 KB -