답안 #985903

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
985903 2024-05-19T09:32:01 Z alexdd One-Way Streets (CEOI17_oneway) C++17
100 / 100
113 ms 29520 KB
#include<iostream>
#include<vector>
using namespace std;
const int INF = 1e9;
int n,m,p;
pair<int,int> e[100005];
int xr[100005];
vector<int> con[100005];
vector<int> relatii[100005];
bool visited[100005],visited_init[100005];
int mind[100005][3];///1 - in sus
int depth[100005];
int tin[100005],tout[100005],timer;
char rez[100005];
int anc[100005][17];
void dfs_init(int nod)
{
    visited_init[nod]=1;
    tin[nod]=++timer;
    for(auto x:con[nod])
    {
        int adj = nod ^ xr[x];
        if(!visited_init[adj])
        {
            anc[adj][0]=nod;
            dfs_init(adj);
        }
    }
    tout[nod]=++timer;
}
bool isanc(int x, int y)
{
    if(tin[x]<=tin[y] && tout[x]>=tout[y])
        return 1;
    return 0;
}
void dfs(int nod, int par)
{
    visited[nod]=1;
    mind[nod][0]=mind[nod][1]=mind[nod][2]=INF;
    for(auto x:con[nod])
    {
        if(x==par)
            continue;
        int adj = nod ^ xr[x];
        if(!visited[adj])
        {
            depth[adj] = depth[nod]+1;
            dfs(adj,x);
            for(int i=0;i<3;i++) mind[nod][i] = min(mind[nod][i], mind[adj][i]);
        }
        else
        {
            rez[x] = 'B';
            mind[nod][0] = min(mind[nod][0], depth[adj]);
        }
    }
    for(auto x:relatii[nod])
    {
        if(x<0)
        {
            x = -x;
            mind[nod][2] = min(mind[nod][2], depth[x]);
        }
        else
        {
            mind[nod][1] = min(mind[nod][1], depth[x]);
        }
    }
    if(par==0)
        return;
    if(mind[nod][0] < depth[nod])
    {
        rez[par] = 'B';
    }
    else///bridge
    {

        if(mind[nod][1] >= depth[nod] && mind[nod][2] >= depth[nod])
            rez[par] = 'B';
        else
        {
            if(e[par].first==nod)
            {
                if(mind[nod][1] >= depth[nod]) rez[par] = 'R';
                else rez[par] = 'L';
            }
            else
            {
                if(mind[nod][1] >= depth[nod]) rez[par] = 'L';
                else rez[par] = 'R';
            }
        }
        //rez[par]='X';
    }
}
int lca(int x, int y)
{
    if(isanc(x,y))
        return x;
    if(isanc(y,x))
        return y;
    for(int i=16;i>=0;i--)
        if(!isanc(anc[x][i],y))
            x = anc[x][i];
    return anc[x][0];
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m;
    int a,b;
    for(int i=1;i<=m;i++)
    {
        cin>>e[i].first>>e[i].second;
        con[e[i].first].push_back(i);
        con[e[i].second].push_back(i);
        xr[i] = e[i].first ^ e[i].second;
    }
    for(int i=1;i<=n;i++)
    {
        if(!visited_init[i])
        {
            dfs_init(i);
            anc[i][0]=1;
        }
    }
    for(int k=1;k<17;k++)
        for(int i=1;i<=n;i++)
            anc[i][k] = anc[anc[i][k-1]][k-1];
    cin>>p;
    for(int i=1;i<=p;i++)
    {
        cin>>a>>b;
        int lc = lca(a,b);
        relatii[a].push_back(-lc);
        relatii[b].push_back(lc);
    }
    for(int i=1;i<=n;i++)
        if(!visited[i])
            dfs(i,0);
    for(int i=1;i<=m;i++)
        cout<<rez[i];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5212 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 3 ms 5212 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5212 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 3 ms 5212 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
11 Correct 29 ms 11096 KB Output is correct
12 Correct 39 ms 13160 KB Output is correct
13 Correct 41 ms 15952 KB Output is correct
14 Correct 46 ms 19028 KB Output is correct
15 Correct 51 ms 20048 KB Output is correct
16 Correct 45 ms 18780 KB Output is correct
17 Correct 46 ms 20824 KB Output is correct
18 Correct 50 ms 18772 KB Output is correct
19 Correct 47 ms 22096 KB Output is correct
20 Correct 34 ms 14424 KB Output is correct
21 Correct 33 ms 14260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5212 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 3 ms 5212 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
10 Correct 3 ms 5212 KB Output is correct
11 Correct 29 ms 11096 KB Output is correct
12 Correct 39 ms 13160 KB Output is correct
13 Correct 41 ms 15952 KB Output is correct
14 Correct 46 ms 19028 KB Output is correct
15 Correct 51 ms 20048 KB Output is correct
16 Correct 45 ms 18780 KB Output is correct
17 Correct 46 ms 20824 KB Output is correct
18 Correct 50 ms 18772 KB Output is correct
19 Correct 47 ms 22096 KB Output is correct
20 Correct 34 ms 14424 KB Output is correct
21 Correct 33 ms 14260 KB Output is correct
22 Correct 96 ms 24144 KB Output is correct
23 Correct 113 ms 23968 KB Output is correct
24 Correct 94 ms 23880 KB Output is correct
25 Correct 90 ms 29520 KB Output is correct
26 Correct 94 ms 25428 KB Output is correct
27 Correct 99 ms 23892 KB Output is correct
28 Correct 24 ms 9564 KB Output is correct
29 Correct 74 ms 18256 KB Output is correct
30 Correct 72 ms 18516 KB Output is correct
31 Correct 83 ms 18944 KB Output is correct
32 Correct 76 ms 22608 KB Output is correct