Submission #794797

# Submission time Handle Problem Language Result Execution time Memory
794797 2023-07-26T23:03:51 Z Magikarp4000 Simurgh (IOI17_simurgh) C++17
0 / 100
2 ms 2644 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n' 
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;

const int MAXN = 1e5+5;
int n,m;
int p[MAXN], sz[MAXN];
vector<int> e, res;
vector<PII> v[MAXN];
bool z[MAXN];

int finds(int x) {
    if (p[x] != x) p[x] = finds(p[x]);
    return p[x];
}

void unite(int a, int b, int idx) {
    a = finds(a);
    b = finds(b);
    if (a != b) {
        if (sz[a] < sz[b]) swap(a,b);
        p[b] = a;
        sz[a] += sz[b];
        e.PB(idx);
    }
}

std::vector<int> find_roads(int N, std::vector<int> U, std::vector<int> V) {
    n = N; m = U.size();
    FOR(i,0,m) v[U[i]].PB({V[i],i}), v[V[i]].PB({U[i],i});
    FOR(i,0,n) {
        e.clear();
        FOR(j,0,n) p[j] = j, sz[j] = 1;
        FOR(j,0,m) {
            if (U[j] != i && V[j] != i) unite(U[j],V[j],j);
        }
        vector<int> w,w1;
        e.PB(v[i][0].S);
        if (!z[v[i][0].S]) w.PB(v[i][0].S);
        int orig = count_common_roads(e);
        z[v[i][0].S] = 1;
        e.pop_back();
        bool sm = 0;
        FORX(u,v[i]) {
            if (z[u.S]) continue;
            z[u.S] = 1;
            e.PB(u.S);
            // cout << i << " " << u.F << ": ";
            // FORX(y,e) cout << y << " ";
            // cout << ln;
            int cur = count_common_roads(e);
            e.pop_back();
            if (cur > orig) sm = 1, w1.PB(u.S);
            else if (cur == orig) w.PB(u.S);
        }
        if (sm == 0) FORX(u,w) res.PB(u);
        else FORX(u,w1) res.PB(u); 
    }
    // FORX(u,res) cout << u << " ";
    // cout << ln;
    return res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB correct
2 Incorrect 2 ms 2644 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB WA in grader: NO
2 Halted 0 ms 0 KB -