Submission #465727

# Submission time Handle Problem Language Result Execution time Memory
465727 2021-08-16T17:14:11 Z AmirElarbi Senior Postmen (BOI14_postmen) C++14
0 / 100
500 ms 25280 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define fi first
#define se second
#define INF 1e7
#define unsigned u
#define eps 1e-18
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MAX_A 100005
#define V 450
#define re register
#define maxi(a,b) ((a) > (b) ? (a) : (b))
using namespace std;
set<int> adj[500005];
bool vis[500005];
int n,m,used;
bool dfs(int u, int p, int start){
    vis[u] = 1;
    for(auto x : adj[u])
    {
        //cout << adj[u].size() << endl;
        if(x == p)
            continue;
        if(x == start)
        {
            //cout << used << " " << m << endl;
            adj[u].erase(x);
            adj[x].erase(u);
            used++;
            if(used == m)
                return true;
            for (int i = 1; i <= n; ++i)
            {
                //cout << i << endl;
                memset(vis, 0, sizeof vis);
                
                if(dfs(i,-1,i)){
                    cout  << i << endl;
                    return true;
                }
            }
            used--;
            adj[u].insert(x);
            adj[x].insert(u);
            return false;
        }
        if(vis[x])
            continue;
        used++;
        adj[u].erase(x);
        adj[x].erase(u);
        if(dfs(x,u,start)){
            cout << x << " ";
            return true;
        }
        used--;
        adj[u].insert(x);
        adj[x].insert(u);
    }
    return false;
}
int main(){
    optimise;
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        int a,b;
        cin >> a >>b;
        adj[a].insert(b);
        adj[b].insert(a);
    }
    for (int i = 1; i <= n; ++i)
    {
        memset(vis, 0, sizeof vis);
        used = 0;
        if(dfs(i,-1,i)){
            cout << i;
            return 0;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 24268 KB Output is correct
2 Correct 14 ms 24268 KB Output is correct
3 Correct 14 ms 24292 KB Output is correct
4 Correct 35 ms 24840 KB Output is correct
5 Correct 28 ms 24448 KB Output is correct
6 Execution timed out 1088 ms 25280 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 24268 KB Output is correct
2 Correct 15 ms 24188 KB Output is correct
3 Correct 13 ms 24268 KB Output is correct
4 Correct 34 ms 24956 KB Output is correct
5 Correct 32 ms 24516 KB Output is correct
6 Execution timed out 1091 ms 25116 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 24268 KB Output is correct
2 Correct 13 ms 24268 KB Output is correct
3 Correct 14 ms 24268 KB Output is correct
4 Correct 40 ms 24836 KB Output is correct
5 Correct 29 ms 24468 KB Output is correct
6 Execution timed out 1095 ms 25152 KB Time limit exceeded
7 Halted 0 ms 0 KB -