Submission #359061

# Submission time Handle Problem Language Result Execution time Memory
359061 2021-01-26T09:46:48 Z talant117408 Simurgh (IOI17_simurgh) C++17
0 / 100
1 ms 1004 KB
#include "simurgh.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;

const int N = 5003;
vector <vector <pii>> graph(N), mutable_graph(N);
vector <int> edges, s, cycle;
map <pii, int> id;
bool used[N], used_edges[N*4];

void _initial(int v){
    used[v] = 1;
    for(auto to : graph[v]){
        if(used[to.first]) continue;
        edges.pb(to.second);
        _initial(to.first);
    }
}

void dfs(int v){
    used[v] = 1;
    s.pb(v);
    for(auto to : mutable_graph[v]){
        if(used[to.first] == 1){
            int flag = 0;
            for(auto to2 : s){
                if(to2 == to.first) flag++;
                if(flag) cycle.pb(to2);
            }
        }
        if(!used[to.first]){
            dfs(to.first);
        }
    }
    used[v] = 2;
    s.pop_back();
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
    if(n > 240) exit(0);
	vector <int> ans;
    for(int i = 0; i < sz(u); i++){
        graph[u[i]].pb(mp(v[i], i));
        graph[v[i]].pb(mp(u[i], i));
        id[mp(min(u[i], v[i]), max(u[i], v[i]))] = i;
    }
    _initial(0);
    for(int i = 0; i < n; i++) used[i] = 0;
    int mx = count_common_roads(edges);
    ans = edges;
    for(auto to : ans) used_edges[to] = 1;
    
    for(int i = 0; i < sz(u); i++){
        if(used_edges[i]) continue;
        vector <int> cycle_num;
        for(auto to : edges){
            mutable_graph[u[to]].pb(mp(v[to], to));
            mutable_graph[v[to]].pb(mp(u[to], to));
        }
        mutable_graph[u[i]].pb(mp(v[i], i));
        mutable_graph[v[i]].pb(mp(u[i], i));
        dfs(u[i]);
        
        for(int j = 0; j < sz(cycle); j++){
            if((cycle[j] == u[i] && cycle[(j+1)%sz(cycle)] == v[i]) || (cycle[j] == v[i] && cycle[(j+1)%sz(cycle)] == u[i]))
                continue;
            cycle_num.pb(id[mp(min(cycle[j], cycle[(j%1)+sz(cycle)]), max(cycle[j], cycle[(j+1)%sz(cycle)]))]);
        }
        sort(all(cycle_num));
        
        set <int> tmp;
        for(auto to : edges) tmp.insert(to);
        tmp.insert(i);
        for(auto to : cycle_num){
            tmp.erase(tmp.find(to));
            vector <int> g;
            for(auto to : tmp) g.pb(to);
            auto p = count_common_roads(g);
            if(p > mx){
                mx = p;
                edges = g;
                break;
            }
            tmp.insert(to);
        }
        
        cycle.clear();
        for(int j = 0; j < n; j++) graph[j].clear();
        for(int j = 0; j < n; j++) used[j] = 0;
        used_edges[i] = 1;
    }
    return edges;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1004 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1004 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1004 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 620 KB correct
2 Runtime error 1 ms 1004 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1004 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -