답안 #936061

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936061 2024-03-01T05:42:15 Z vjudge1 Rigged Roads (NOI19_riggedroads) C++17
100 / 100
261 ms 39116 KB
#include <bits/stdc++.h>
using namespace std;
int n,e,a[300001],b[300001],r,mst[300001],p[300001],d[300001],l[300001],id,res[300001];
vector <int> ke[300001],ve;
int f(int i){
    return (l[i]==i?i:l[i]=f(l[i]));
}
void unite(int i, int j){
    l[f(j)]=f(i);
}
void dfs(int u, int par){
    for (int i:ke[u]){
        int v=a[i]^b[i]^u;
        if (v!=par){
            p[v]=i;
            d[v]=d[u]+1;
            dfs(v,u);
        }
    }
}
void walk(int u, int v){
    ve.clear();
    while (true){
        u=f(u);
        v=f(v);
        if (u==v)
            break;
        if (d[u]<d[v])
            swap(u,v);
        int i=p[u];
        unite(a[i]^b[i]^u,u);
        ve.push_back(i);
    }
    sort(ve.begin(),ve.end());
    for (int i:ve)
        res[i]=++id;
}
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n >> e;
    for (int i=1;i<=e;i++)
        cin >> a[i] >> b[i];
    for (int i=1;i<n;i++){
        cin >> r;
        mst[r]=1;
        ke[a[r]].push_back(r);
        ke[b[r]].push_back(r);
    }
    iota(l,l+n+1,0);
    dfs(1,1);
    for (int i=1;i<=e;i++){
        if (!res[i]){
            walk(a[i],b[i]);
            if (!res[i])
                res[i]=++id;
        }
        cout << res[i] << ' ';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 3 ms 12888 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 3 ms 12888 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 4 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12888 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 19064 KB Output is correct
2 Correct 55 ms 20872 KB Output is correct
3 Correct 72 ms 16132 KB Output is correct
4 Correct 91 ms 26956 KB Output is correct
5 Correct 96 ms 27428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 26056 KB Output is correct
2 Correct 34 ms 17232 KB Output is correct
3 Correct 19 ms 14940 KB Output is correct
4 Correct 45 ms 23008 KB Output is correct
5 Correct 17 ms 16220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 33996 KB Output is correct
2 Correct 166 ms 39116 KB Output is correct
3 Correct 35 ms 21452 KB Output is correct
4 Correct 50 ms 24660 KB Output is correct
5 Correct 184 ms 37768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 29128 KB Output is correct
2 Correct 55 ms 24668 KB Output is correct
3 Correct 209 ms 33672 KB Output is correct
4 Correct 261 ms 31692 KB Output is correct
5 Correct 14 ms 13912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 3 ms 12888 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 4 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12888 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
9 Correct 34 ms 19064 KB Output is correct
10 Correct 55 ms 20872 KB Output is correct
11 Correct 72 ms 16132 KB Output is correct
12 Correct 91 ms 26956 KB Output is correct
13 Correct 96 ms 27428 KB Output is correct
14 Correct 63 ms 26056 KB Output is correct
15 Correct 34 ms 17232 KB Output is correct
16 Correct 19 ms 14940 KB Output is correct
17 Correct 45 ms 23008 KB Output is correct
18 Correct 17 ms 16220 KB Output is correct
19 Correct 157 ms 33996 KB Output is correct
20 Correct 166 ms 39116 KB Output is correct
21 Correct 35 ms 21452 KB Output is correct
22 Correct 50 ms 24660 KB Output is correct
23 Correct 184 ms 37768 KB Output is correct
24 Correct 95 ms 29128 KB Output is correct
25 Correct 55 ms 24668 KB Output is correct
26 Correct 209 ms 33672 KB Output is correct
27 Correct 261 ms 31692 KB Output is correct
28 Correct 14 ms 13912 KB Output is correct
29 Correct 187 ms 31924 KB Output is correct
30 Correct 217 ms 31176 KB Output is correct
31 Correct 179 ms 28112 KB Output is correct
32 Correct 54 ms 16464 KB Output is correct
33 Correct 192 ms 28864 KB Output is correct