Submission #887084

# Submission time Handle Problem Language Result Execution time Memory
887084 2023-12-13T16:43:54 Z maxFedorchuk One-Way Streets (CEOI17_oneway) C++14
100 / 100
272 ms 42448 KB
#include <bits/stdc++.h>
using namespace std;

const long long MX=1e5+10;

vector < pair < long long , long long > > mas[MX];
map < pair < long long , long long > , long long > reb;
pair < long long , long long > rb[MX];

vector < long long > mosty_in;
long long real_mosty[MX];

long long tin[MX],tou[MX];
long long timer=0;

void CNTMOST(long long zar,long long mun)
{
    timer++;
    tin[zar]=timer;
    tou[zar]=timer;

    for(auto u:mas[zar])
    {
        if(mun==u.first)
        {
            continue;
        }

        if(tin[u.first]==0)
        {
            CNTMOST(u.first,zar);
            tou[zar]=min(tou[zar],tou[u.first]);

            if(tou[u.first]>tin[zar])
            {
                mosty_in.push_back(u.second);
            }
        }
        else
        {
            tou[zar]=min(tou[zar],tin[u.first]);
        }
    }

    return;
}

long long vis[MX];
long long tmm=0;

void DFS(long long zar)
{
    vis[zar]=tmm;
    for(auto u:mas[zar])
    {
        if(!vis[u.first] && real_mosty[u.second]==0)
        {
            DFS(u.first);
        }
    }

    return;
}

long long prfs[MX];
long long vis2[MX];

map < pair < long long , long long > , long long > res2;

void DFS2(long long zar,long long mun)
{
    vis2[zar]=1;

    for(auto u:mas[zar])
    {
        if(u.first!=mun)
        {
            DFS2(u.first,zar);
            prfs[zar]+=prfs[u.first];
        }
    }

    if(prfs[zar]!=0)
    {
        if(prfs[zar]>0)
        {
            res2[{zar,mun}]=1;
        }
        else
        {
            res2[{mun,zar}]=1;
        }
    }

    return;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    long long n,m;
    cin>>n>>m;

    for(long long i=1;i<=m;i++)
    {
        cin>>rb[i].first>>rb[i].second;

        if(rb[i].first!=rb[i].second)
        {
            if(reb.find({rb[i].first,rb[i].second})==reb.end())
            {
                mas[rb[i].first].push_back({rb[i].second,i});
                mas[rb[i].second].push_back({rb[i].first,i});
            }
        }

        reb[{rb[i].first,rb[i].second}]++;
        reb[{rb[i].second,rb[i].first}]++;
    }

    for(long long i=1;i<=n;i++)
    {
        if(tin[i]==0)
        {
            CNTMOST(i,0);
        }
    }

    for(auto u:mosty_in)
    {
        if(reb[{rb[u].first,rb[u].second}]==1)
        {
            real_mosty[u]=1;
        }
    }


    for(long long i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            tmm++;
            DFS(i);
        }
    }

    for(long long i=1;i<=n;i++)
    {
        mas[i].clear();
    }

    for(long long i=1;i<=m;i++)
    {
        if(real_mosty[i])
        {
            mas[vis[rb[i].first]].push_back({vis[rb[i].second],i});
            mas[vis[rb[i].second]].push_back({vis[rb[i].first],i});
        }
    }

    long long q;
    cin>>q;

    long long a,b;
    while(q--)
    {
        cin>>a>>b;

        prfs[vis[a]]++;
        prfs[vis[b]]--;
    }

    for(long long i=1;i<=n;i++)
    {
        if(vis2[i]==0)
        {
            DFS2(i,0);
        }
    }

    for(long long i=1;i<=m;i++)
    {
        if(!real_mosty[i])
        {
            cout<<"B";
            continue;
        }

        if(res2.find({vis[rb[i].first],vis[rb[i].second]})!=res2.end())
        {
            cout<<"R";
            continue;
        }

        if(res2.find({vis[rb[i].second],vis[rb[i].first]})!=res2.end())
        {
            cout<<"L";
        }
        else
        {
            cout<<"B";
        }
    }

    cout<<"\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5064 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5064 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 146 ms 25532 KB Output is correct
12 Correct 146 ms 27220 KB Output is correct
13 Correct 166 ms 29116 KB Output is correct
14 Correct 184 ms 30668 KB Output is correct
15 Correct 173 ms 30800 KB Output is correct
16 Correct 203 ms 28896 KB Output is correct
17 Correct 203 ms 33492 KB Output is correct
18 Correct 241 ms 28984 KB Output is correct
19 Correct 207 ms 35140 KB Output is correct
20 Correct 120 ms 26500 KB Output is correct
21 Correct 102 ms 25680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 5064 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 146 ms 25532 KB Output is correct
12 Correct 146 ms 27220 KB Output is correct
13 Correct 166 ms 29116 KB Output is correct
14 Correct 184 ms 30668 KB Output is correct
15 Correct 173 ms 30800 KB Output is correct
16 Correct 203 ms 28896 KB Output is correct
17 Correct 203 ms 33492 KB Output is correct
18 Correct 241 ms 28984 KB Output is correct
19 Correct 207 ms 35140 KB Output is correct
20 Correct 120 ms 26500 KB Output is correct
21 Correct 102 ms 25680 KB Output is correct
22 Correct 244 ms 38348 KB Output is correct
23 Correct 272 ms 35780 KB Output is correct
24 Correct 256 ms 35536 KB Output is correct
25 Correct 223 ms 42448 KB Output is correct
26 Correct 229 ms 37380 KB Output is correct
27 Correct 254 ms 35984 KB Output is correct
28 Correct 50 ms 6644 KB Output is correct
29 Correct 141 ms 27204 KB Output is correct
30 Correct 144 ms 27220 KB Output is correct
31 Correct 149 ms 27948 KB Output is correct
32 Correct 137 ms 29316 KB Output is correct