Submission #49971

#TimeUsernameProblemLanguageResultExecution timeMemory
49971BenqSimurgh (IOI17_simurgh)C++14
30 / 100
120 ms5352 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

#include "simurgh.h"

vpi adj[500];
int comp[500];
vi tre[500], tmp[500], allComp;
int n;
bool need[500*499/2], sec[500*499/2];
vi u,v;

template<int SZ> struct DSU {
    int par[SZ], sz[SZ];
    DSU() {
        F0R(i,SZ) par[i] = i, sz[i] = 1;
    }
    
    int get(int x) { // path compression
    	if (par[x] != x) par[x] = get(par[x]);
    	return par[x];
    }
    
    bool unite(int x, int y) { // union-by-rank
    	x = get(x), y = get(y);
    	if (x == y) return 0;
    	if (sz[x] < sz[y]) swap(x,y);
    	sz[x] += sz[y], par[y] = x;
    	return 1;
    }
};


/*int count_common_roads(vi z) {
    DSU<500> D = DSU<500>();
    int ret = 0;
    for (int i: z) {
        if (!D.unite(u[i],v[i])) exit(5);
        if (sec[i]) ret ++;
    }
    return ret;
}*/

void test(int a, int b) {
    pair<int,vi> bes = {0,{}};
    for (int x: tmp[b]) {
        vi z = {x};
        for (int i: allComp) {
            if (i != b) z.pb(tmp[i].back());
            z.insert(z.end(),all(tre[i]));
        }
        int Z = count_common_roads(z);
        if (Z > bes.f) bes.f = Z, bes.s.clear();
        if (Z == bes.f) bes.s.pb(x);
    }
    for (int i: bes.s) need[i] = 1;
}

void dfs(int x, int lab, int ind) {
    comp[x] = lab;
    for (auto a: adj[x]) if (comp[a.f] == -1) {
        tre[lab].pb(a.s);
        dfs(a.f,lab,ind);
    }
}

void gen(int ind) {
    F0R(i,n) {
        comp[i] = -1;
        tre[i].clear();
        tmp[i].clear();
    }
    comp[ind] = ind;
    
    allComp.clear();
    F0R(i,n) if (i != ind && comp[i] == -1) {
        allComp.pb(i);
        dfs(i,i,ind);
    }
    for (auto a: adj[ind]) tmp[comp[a.f]].pb(a.s);
}

void test(int ind) {
    gen(ind);
    for (int i: allComp) test(ind,i);
}

vector<int> find_roads(int N, vi U, vi V) {
    n = N, u = U, v = V;
    
    F0R(i,sz(u)) {
        // cout << u[i] << " " << v[i] << "\n";
        adj[u[i]].pb({v[i],i});
        adj[v[i]].pb({u[i],i});
    }
    F0R(i,n) test(i);
    
    vi ans;
    F0R(i,sz(u)) if (need[i]) ans.pb(i);
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...