Submission #242841

# Submission time Handle Problem Language Result Execution time Memory
242841 2020-06-29T11:31:16 Z gs18115 Rigged Roads (NOI19_riggedroads) C++14
100 / 100
518 ms 62408 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
int spa[300010][18],dp[300010];
inline int lca(int x,int y)
{
    if(dp[x]<dp[y])
        swap(x,y);
    for(int i=dp[x]-dp[y];i>0;i^=i&-i)
        x=spa[x][__builtin_ctz(i)];
    if(x==y)
        return x;
    for(int i=18;i-->0;)
        if(spa[x][i]!=spa[y][i])
            x=spa[x][i],y=spa[y][i];
    return spa[x][0];
}
vector<pi>adj[300010];
int paw[300010];
void dfs(int x,int p)
{
    dp[x]=dp[p]+1;
    spa[x][0]=p;
    for(int i=0;i<17;i++)
        spa[x][i+1]=spa[spa[x][i]][i];
    for(pi&t:adj[x])
        if(t.fi!=p)
            paw[t.fi]=t.se,dfs(t.fi,x);
    return;
}
int u[300010],v[300010];
bool inl[300010],used[300010];
int pa[300010],ans[300010];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,e;
    cin>>n>>e;
    for(int i=0;i++<e;)
        cin>>u[i]>>v[i];
    vector<int>lst(n-1);
    for(int&t:lst)
    {
        cin>>t;
        adj[u[t]].eb(v[t],t);
        adj[v[t]].eb(u[t],t);
        inl[t]=1;
    }
    paw[1]=inf;
    dfs(1,0);
    int ccn=0;
    used[1]=1;
    for(int i=1;i++<n;)
        pa[i]=spa[i][0];
    for(int i=0;i++<e;)
    {
        if(inl[i])
        {
            if(ans[i]==0)
                ans[i]=++ccn,used[dp[u[i]]>dp[v[i]]?u[i]:v[i]]=1;
            continue;
        }
        vector<int>ls;
        int l=lca(u[i],v[i]);
        int cu,cv;
        for(cu=u[i];dp[cu]>dp[l];cu=pa[cu])
            if(!used[cu])
                ls.eb(paw[cu]),used[cu]=1;
        for(cv=u[i];dp[cv]>dp[cu];)
        {
            int nxt=pa[cv];
            pa[cv]=cu;
            cv=nxt;
        }
        for(cu=v[i];dp[cu]>dp[l];cu=pa[cu])
            if(!used[cu])
                ls.eb(paw[cu]),used[cu]=1;
        for(cv=v[i];dp[cv]>dp[cu];)
        {
            int nxt=pa[cv];
            pa[cv]=cu;
            cv=nxt;
        }
        sort(all(ls));
        for(int&t:ls)
            ans[t]=++ccn;
        ans[i]=++ccn;
    }
    for(int i=0;i++<e;)
        cout<<ans[i]<<' ';
    cout<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 11 ms 7552 KB Output is correct
5 Correct 10 ms 7552 KB Output is correct
6 Correct 10 ms 7552 KB Output is correct
7 Correct 12 ms 7552 KB Output is correct
8 Correct 10 ms 7552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 23148 KB Output is correct
2 Correct 128 ms 29812 KB Output is correct
3 Correct 100 ms 18292 KB Output is correct
4 Correct 163 ms 51040 KB Output is correct
5 Correct 174 ms 53216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 29988 KB Output is correct
2 Correct 74 ms 17400 KB Output is correct
3 Correct 42 ms 12536 KB Output is correct
4 Correct 87 ms 24016 KB Output is correct
5 Correct 33 ms 14208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 349 ms 52044 KB Output is correct
2 Correct 316 ms 57800 KB Output is correct
3 Correct 79 ms 21652 KB Output is correct
4 Correct 142 ms 28816 KB Output is correct
5 Correct 417 ms 62408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 282 ms 37728 KB Output is correct
2 Correct 182 ms 28408 KB Output is correct
3 Correct 503 ms 56216 KB Output is correct
4 Correct 388 ms 52984 KB Output is correct
5 Correct 28 ms 11776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 11 ms 7552 KB Output is correct
5 Correct 10 ms 7552 KB Output is correct
6 Correct 10 ms 7552 KB Output is correct
7 Correct 12 ms 7552 KB Output is correct
8 Correct 10 ms 7552 KB Output is correct
9 Correct 69 ms 23148 KB Output is correct
10 Correct 128 ms 29812 KB Output is correct
11 Correct 100 ms 18292 KB Output is correct
12 Correct 163 ms 51040 KB Output is correct
13 Correct 174 ms 53216 KB Output is correct
14 Correct 112 ms 29988 KB Output is correct
15 Correct 74 ms 17400 KB Output is correct
16 Correct 42 ms 12536 KB Output is correct
17 Correct 87 ms 24016 KB Output is correct
18 Correct 33 ms 14208 KB Output is correct
19 Correct 349 ms 52044 KB Output is correct
20 Correct 316 ms 57800 KB Output is correct
21 Correct 79 ms 21652 KB Output is correct
22 Correct 142 ms 28816 KB Output is correct
23 Correct 417 ms 62408 KB Output is correct
24 Correct 282 ms 37728 KB Output is correct
25 Correct 182 ms 28408 KB Output is correct
26 Correct 503 ms 56216 KB Output is correct
27 Correct 388 ms 52984 KB Output is correct
28 Correct 28 ms 11776 KB Output is correct
29 Correct 507 ms 51468 KB Output is correct
30 Correct 518 ms 53712 KB Output is correct
31 Correct 476 ms 53024 KB Output is correct
32 Correct 115 ms 18040 KB Output is correct
33 Correct 414 ms 53388 KB Output is correct