# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
909547 | 2024-01-17T09:02:47 Z | ttamx | Rigged Roads (NOI19_riggedroads) | C++14 | 714 ms | 262144 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 12632 KB | Output is correct |
2 | Correct | 3 ms | 12636 KB | Output is correct |
3 | Correct | 3 ms | 12636 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 12632 KB | Output is correct |
2 | Correct | 3 ms | 12636 KB | Output is correct |
3 | Correct | 3 ms | 12636 KB | Output is correct |
4 | Correct | 4 ms | 12636 KB | Output is correct |
5 | Correct | 4 ms | 12784 KB | Output is correct |
6 | Correct | 4 ms | 12636 KB | Output is correct |
7 | Correct | 4 ms | 12636 KB | Output is correct |
8 | Correct | 3 ms | 12780 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 19404 KB | Output is correct |
2 | Correct | 62 ms | 22748 KB | Output is correct |
3 | Correct | 60 ms | 19400 KB | Output is correct |
4 | Correct | 97 ms | 32240 KB | Output is correct |
5 | Correct | 103 ms | 33204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 56 ms | 26748 KB | Output is correct |
2 | Correct | 37 ms | 18768 KB | Output is correct |
3 | Correct | 19 ms | 15708 KB | Output is correct |
4 | Correct | 42 ms | 23084 KB | Output is correct |
5 | Correct | 18 ms | 17036 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 714 ms | 262144 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 116 ms | 30776 KB | Output is correct |
2 | Correct | 68 ms | 25496 KB | Output is correct |
3 | Correct | 234 ms | 39660 KB | Output is correct |
4 | Correct | 199 ms | 37460 KB | Output is correct |
5 | Correct | 21 ms | 14680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 12632 KB | Output is correct |
2 | Correct | 3 ms | 12636 KB | Output is correct |
3 | Correct | 3 ms | 12636 KB | Output is correct |
4 | Correct | 4 ms | 12636 KB | Output is correct |
5 | Correct | 4 ms | 12784 KB | Output is correct |
6 | Correct | 4 ms | 12636 KB | Output is correct |
7 | Correct | 4 ms | 12636 KB | Output is correct |
8 | Correct | 3 ms | 12780 KB | Output is correct |
9 | Correct | 41 ms | 19404 KB | Output is correct |
10 | Correct | 62 ms | 22748 KB | Output is correct |
11 | Correct | 60 ms | 19400 KB | Output is correct |
12 | Correct | 97 ms | 32240 KB | Output is correct |
13 | Correct | 103 ms | 33204 KB | Output is correct |
14 | Correct | 56 ms | 26748 KB | Output is correct |
15 | Correct | 37 ms | 18768 KB | Output is correct |
16 | Correct | 19 ms | 15708 KB | Output is correct |
17 | Correct | 42 ms | 23084 KB | Output is correct |
18 | Correct | 18 ms | 17036 KB | Output is correct |
19 | Runtime error | 714 ms | 262144 KB | Execution killed with signal 9 |
20 | Halted | 0 ms | 0 KB | - |