Submission #909553

# Submission time Handle Problem Language Result Execution time Memory
909553 2024-01-17T09:07:30 Z ttamx Rigged Roads (NOI19_riggedroads) C++14
100 / 100
363 ms 43380 KB
#include<bits/stdc++.h>

using namespace std;

const int N=3e5+5;

int n,m;
pair<int,int> edge[N];
vector<pair<int,int>> adj[N];
int pa[N],pid[N],lv[N];
int fa[N];
int ans[N];
bool ok[N];

int fp(int u){
    return fa[u]=u==fa[u]?u:fp(fa[u]);
}

void dfs(int u,int p=0){
    lv[u]=lv[p]+1;
    for(auto [v,i]:adj[u])if(v!=p){
        pa[v]=u;
        pid[v]=i;
        dfs(v,u);
    }
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        auto &[u,v]=edge[i];
        cin >> u >> v;
    }
    for(int i=1;i<n;i++){
        int x;
        cin >> x;
        auto [u,v]=edge[x];
        adj[u].emplace_back(v,x);
        adj[v].emplace_back(u,x);
        ok[x]=true;
    }
    dfs(1);
    for(int i=1;i<=n;i++)fa[i]=i;
    int cnt=1;
    for(int i=1;i<=m;i++){
        if(ans[i])continue;
        auto [u,v]=edge[i];
        u=fp(u),v=fp(v);
        vector<int> res;
        while(u!=v){
            if(lv[u]<lv[v])swap(u,v);
            res.emplace_back(pid[u]);
            u=fa[u]=fp(pa[u]);
        }
        sort(res.begin(),res.end());
        for(auto j:res)ans[j]=cnt++;
        if(!ok[i])ans[i]=cnt++;
    }
    for(int i=1;i<=m;i++)cout << ans[i] << " ";
}

Compilation message

riggedroads.cpp: In function 'void dfs(int, int)':
riggedroads.cpp:21:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   21 |     for(auto [v,i]:adj[u])if(v!=p){
      |              ^
riggedroads.cpp: In function 'int main()':
riggedroads.cpp:32:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   32 |         auto &[u,v]=edge[i];
      |               ^
riggedroads.cpp:38:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |         auto [u,v]=edge[x];
      |              ^
riggedroads.cpp:48:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   48 |         auto [u,v]=edge[i];
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 3 ms 12632 KB Output is correct
3 Correct 4 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 3 ms 12632 KB Output is correct
3 Correct 4 ms 12636 KB Output is correct
4 Correct 4 ms 12636 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 3 ms 12632 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 5 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 17984 KB Output is correct
2 Correct 64 ms 20164 KB Output is correct
3 Correct 59 ms 16332 KB Output is correct
4 Correct 99 ms 28064 KB Output is correct
5 Correct 98 ms 28860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 24316 KB Output is correct
2 Correct 34 ms 17116 KB Output is correct
3 Correct 18 ms 14936 KB Output is correct
4 Correct 41 ms 21292 KB Output is correct
5 Correct 17 ms 16220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 37792 KB Output is correct
2 Correct 170 ms 43024 KB Output is correct
3 Correct 43 ms 20960 KB Output is correct
4 Correct 54 ms 25308 KB Output is correct
5 Correct 327 ms 43380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 27852 KB Output is correct
2 Correct 81 ms 23700 KB Output is correct
3 Correct 257 ms 34560 KB Output is correct
4 Correct 184 ms 32780 KB Output is correct
5 Correct 14 ms 14168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 3 ms 12632 KB Output is correct
3 Correct 4 ms 12636 KB Output is correct
4 Correct 4 ms 12636 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 3 ms 12632 KB Output is correct
7 Correct 3 ms 12636 KB Output is correct
8 Correct 5 ms 12636 KB Output is correct
9 Correct 35 ms 17984 KB Output is correct
10 Correct 64 ms 20164 KB Output is correct
11 Correct 59 ms 16332 KB Output is correct
12 Correct 99 ms 28064 KB Output is correct
13 Correct 98 ms 28860 KB Output is correct
14 Correct 57 ms 24316 KB Output is correct
15 Correct 34 ms 17116 KB Output is correct
16 Correct 18 ms 14936 KB Output is correct
17 Correct 41 ms 21292 KB Output is correct
18 Correct 17 ms 16220 KB Output is correct
19 Correct 166 ms 37792 KB Output is correct
20 Correct 170 ms 43024 KB Output is correct
21 Correct 43 ms 20960 KB Output is correct
22 Correct 54 ms 25308 KB Output is correct
23 Correct 327 ms 43380 KB Output is correct
24 Correct 109 ms 27852 KB Output is correct
25 Correct 81 ms 23700 KB Output is correct
26 Correct 257 ms 34560 KB Output is correct
27 Correct 184 ms 32780 KB Output is correct
28 Correct 14 ms 14168 KB Output is correct
29 Correct 271 ms 37884 KB Output is correct
30 Correct 293 ms 37096 KB Output is correct
31 Correct 211 ms 34652 KB Output is correct
32 Correct 55 ms 19540 KB Output is correct
33 Correct 363 ms 35340 KB Output is correct