Submission #591598

# Submission time Handle Problem Language Result Execution time Memory
591598 2022-07-07T16:35:01 Z VasLemmy One-Way Streets (CEOI17_oneway) C++17
0 / 100
4 ms 5436 KB
#include<bits/stdc++.h>
//#define int long long
#define pii pair<int,int>
#define fi first
#define se second
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")*/
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ldb = long double;
const ll N = (int)1e9 + 1;
const int maxN = (int)1e5 + 1;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infty = 1e18 + 7;
const int base = (int)4e5;
const int Block_size = 340;

void InputFile()
{
    freopen("test.inp","r",stdin);
    //freopen("scrivener.out","w",stdout);
    //freopen("test.out","r",stdin);
}

void FastInput()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int n,m,p;
int x[maxN],y[maxN];
vector<pii> adj1[maxN];
map<pii,int> apr;
char res[maxN];
int isbridge[maxN];

string juryoutput;

void Read()
{
    //cin >> juryoutput;
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        cin >> x[i] >> y[i];
        res[i] = 'B';
        if(x[i] == y[i])
        {
            continue;
        }
        if(apr[make_pair(min(x[i],y[i]),max(x[i],y[i]))] == 0)
        {
            adj1[x[i]].push_back({y[i],i});
            adj1[y[i]].push_back({x[i],i});
        }
        apr[make_pair(min(x[i],y[i]),max(x[i],y[i]))]++;
    }
}

int num[maxN],low[maxN];
int TimeDFS = 0;

void preDFS(int u,int pre)
{
    num[u] = low[u] = ++TimeDFS;
    for(pii x : adj1[u])
    {
        if(x.fi == pre) continue;
        if(!num[x.fi])
        {
            preDFS(x.fi,u);
            low[u] = min(low[u],low[x.fi]);
            if(low[x.fi] == num[x.fi] && apr[ {min(u,x.fi),max(u,x.fi)}] == 1)
            {
                isbridge[x.se] = 1;
            }
        }
        else
        {
            low[u] = min(low[u],num[x.fi]);
        }
    }
}

int isvis[maxN];
int cnt_grp = 0;
vector<vector<int>> adj2[maxN];
int grp[maxN];

/// 1 la phai
/// 0 la trai

void DFS_Build(int u)
{
    isvis[u] = 1;
    for(pii t : adj1[u])
    {
        if(isvis[t.fi]) continue;
        if(isbridge[t.se])
        {
            cnt_grp++;
            grp[t.fi] = cnt_grp;
            if(u == x[t.se])
            {
                adj2[grp[u]].push_back({grp[t.fi],t.se,1});
                adj2[grp[t.fi]].push_back({grp[u],t.se,0});
            }
            else
            {
                adj2[grp[u]].push_back({grp[t.fi],t.se,0});
                adj2[grp[t.fi]].push_back({grp[u],t.se,1});
            }
        }
        else grp[t.fi] = grp[u];
        DFS_Build(t.fi);
    }
}

int save_e[maxN];
int anc[25][maxN];
int dp[maxN];
int ifused[maxN];
int depth[maxN];

void DFS2(int u,int p)
{
    for(vector<int> x : adj2[u])
    {
        int v = x[0];
        if(v == p) continue;
        depth[v] = depth[u] + 1;
        save_e[v] = x[1];
        if(x[2] == 1)
        {
            res[x[1]] = 'R';
        }
        else res[x[1]] = 'L';
        anc[0][v] = u;
        for(int i = 1; i <= (int)log2(n); i++)
        {
            anc[i][v] = anc[i-1][anc[i-1][v]];
        }
        DFS2(v,u);
    }
}

void DFS3(int u,int p)
{
    for(vector<int> x : adj2[u])
    {
        int v = x[0];
        if(v == p) continue;
        DFS3(v,u);
        dp[u] += dp[v];
    }
}

void DFS4(int u,int p)
{
    for(vector<int> x : adj2[u])
    {
        int v = x[0];
        if(v == p) continue;
        DFS4(v,u);
        ifused[u] += ifused[v];
    }
}

int LCA(int u,int v)
{
    if(depth[u] < depth[v]) swap(u,v);
    int k = depth[u] - depth[v];
    for(int i = (int)log2(n); i >= 0; i--)
    {
        if(k & (1 << i))
        {
            u = anc[i][u];
        }
    }
    if(u == v) return u;
    for(int i = (int)log2(n); i >= 0; i--)
    {
        if(anc[i][u] != anc[i][v])
        {
            u = anc[i][u];
            v = anc[i][v];
        }
    }
    return anc[0][u];
}

void Solve()
{
    for(int i = 1; i <= n; i++)
    {
        if(!num[i])
        {
            preDFS(i,i);
        }
    }

    for(int i = 1; i <= n; i++)
    {
        if(!isvis[i])
        {
            cnt_grp++;
            grp[i] = cnt_grp;
            DFS_Build(i);
        }
    }
    /*for(int i = 1; i <= n; i++)
    {
        cout << grp[i] <<' ';
    }
    cout <<'\n'<<"dark";
    return;*/

    for(int i = 1; i <= cnt_grp; i++)
    {
        if(depth[i] == 0) DFS2(i,i);
    }
    cin >> p;
    while(p--)
    {
        int a,b;
        cin >> a >> b;
        dp[LCA(grp[a],grp[b])]--;
        dp[grp[a]]++;
        ifused[LCA(grp[a],grp[b])]--;
        ifused[grp[a]]++;
        ifused[grp[b]]++;
    }
    //cout << save_e[2];return;
    for(int i = 1; i <= cnt_grp; i++)
    {
        if(depth[i] == 0)
        {
                DFS3(i,i);
                DFS4(i,i);
        }
    }
    for(int i = 1; i <= cnt_grp; i++)
    {
        if(depth[i] == 0)
        {
            continue;
        }
        if(dp[i] > 0)
        {
            res[save_e[i]] = 'L' + 'R' - res[save_e[i]];
        }
        else if(ifused[i] == 0)
        {
            res[save_e[i]] = 'B';
        }
    }
    string g;
    for(int i = 1; i <= m; i++)
    {
       cout << res[i];
       g.push_back(res[i]);
       //if(res[i] != juryoutput[i-1]) {cout <<"sai o"<<' '<< i <<'\n';}
    }
    //cout << juryoutput <<'\n'<< g <<'\n';
    //if(g == juryoutput) cout <<"OK";
    //else cout <<"SAI CMNR";
}

void Debug()
{

}


int32_t main()
{
    FastInput();
    //InputFile();
    //int sub_type;
    //cin >> sub_type;
    //Sieve();
    //Prepare();
    int test;
    //cin >> test;
    test = 1;
    while(test--)
        //for(int prc = 1; prc <= test; prc++)
    {
        Read();
        Solve();
        //Debug();
    }
}

Compilation message

oneway.cpp: In function 'void InputFile()':
oneway.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     freopen("test.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 4 ms 5204 KB Output is correct
4 Incorrect 4 ms 5436 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 4 ms 5204 KB Output is correct
4 Incorrect 4 ms 5436 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 4 ms 5204 KB Output is correct
4 Incorrect 4 ms 5436 KB Output isn't correct
5 Halted 0 ms 0 KB -