Submission #877185

# Submission time Handle Problem Language Result Execution time Memory
877185 2023-11-23T03:04:16 Z thieunguyenhuy Rigged Roads (NOI19_riggedroads) C++17
0 / 100
9 ms 30812 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vll;
typedef vector<pair<long long, int>> vli;
typedef vector<pair<int, long long>> vil;

#define bitcnt(n) __builtin_popcountll((n))
#define BIT(n, i) (((n) >> (i)) & 1ll)
#define FLIP(n, i) ((n) ^ (1ll << (i)))
#define MASK(i) (1ll << (i))
#define ON(n, i) ((n) | MASK(i))
#define OFF(n, i) ((n) & ~MASK(i))

#define Int __int128
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a / gcd(a, b) * b
#define fi first
#define se second

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

template <class T1, class T2> 
bool maximize(T1 &x, T2 y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
template <class T1, class T2>
bool minimize(T1 &x, T2 y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;

int n, m, dep[N], ans[N], par[N], anc[N], match[N];
bitset<N> keep;
pii edges[N];
vector<int> adj[N];

int find_set(int p) {
    return par[p] == p ? p : par[p] = find_set(par[p]);
}

bool join(int u, int v) {
    u = find_set(u), v = find_set(v);
    if (u == v) return false;
    if (dep[u] < dep[v]) swap(u, v);
    par[u] = v; return true;
}

void dfs(int u) {
    for (auto v : adj[u]) {
        if (dep[v] == -1) {
            dep[v] = dep[u] + 1;
            dfs(v);
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    #ifndef ONLINE_JUDGE
        freopen("input.inp", "r", stdin);
        freopen("output.out", "w", stdout);
    #else
        #define taskname "ZONING"
        if (fopen(taskname".inp", "r")) {
            freopen(taskname".inp", "r", stdin);
            freopen(taskname".out", "w", stdout);
        }
    #endif

    cin >> n >> m;

    for (int i = 1; i <= n; ++i) par[i] = i;

    for (int i = 1; i <= m; ++i) {
        int u, v; cin >> u >> v;
        adj[u].emplace_back(v), adj[v].emplace_back(u);
        edges[i] = make_pair(u, v);
    }

    for (int i = 1; i < n; ++i) {
        int r; cin >> r;
        keep[r] = true;
    }

    memset(dep, -1, sizeof dep); dep[1] = 0; dfs(1);

    for (int i = 1; i <= m; ++i) {
        if (keep[i]) {
            auto [u, v] = edges[i];
            if (dep[u] < dep[v]) swap(u, v);
            match[u] = i, anc[u] = v;
        }
    }

    int w = 0;
    for (int i = 1; i <= m; ++i) {
        if (ans[i] != 0) continue;
        auto [u, v] = edges[i];
        u = find_set(u), v = find_set(v);
        if (!keep[i]) {
            vector<int> ve;
            while (u != v) {
                if (dep[u] < dep[v]) swap(u, v);
                ve.emplace_back(match[u]);
                join(u, anc[u]); u = find_set(u);
            }
            sort (ve.begin(), ve.end());
            for (int i = 0; i < ve.size(); ++i) ans[ve[i]] = ++w;
        }
        else join(u, v);
        ans[i] = ++w;
    }

    for (int i = 1; i <= m; ++i) cout << ans[i] << ' ';
    return 0;
}

Compilation message

riggedroads.cpp: In function 'int main()':
riggedroads.cpp:134:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  134 |             for (int i = 0; i < ve.size(); ++i) ans[ve[i]] = ++w;
      |                             ~~^~~~~~~~~~~
riggedroads.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen("input.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
riggedroads.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen("output.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 30812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 30812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 30812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 30812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 30808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 30812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 30812 KB Output isn't correct
2 Halted 0 ms 0 KB -