답안 #878702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878702 2023-11-25T05:56:41 Z Sir_Ahmed_Imran One-Way Streets (CEOI17_oneway) C++17
60 / 100
3000 ms 19028 KB
                              ///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define li long int
#define ld long double
#define append push_back
#define add insert
#define nl "\n"
#define ff first
#define ss second
#define pii pair<int,int>
#define pic pair<int,char>
#define all(x) (x).begin(),(x).end()
#define sum(a) accumulate(all(a),0) 
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL)
#define terminator main
#define N 100001
char c[N];
int vis[N];
int cup[N];
int Par[N];
int par[N];
int cpar[N];
int dept[N];
pii edge[N];
vector<pii> a[N];
vector<pii> g[N];
int root(int v){
    if(!Par[v]) return v;
    Par[v]=root(Par[v]);
    return Par[v];
}
void merge(int v,int u){
    Par[root(u)]=root(v);
}
bool same(int v,int u){
    return (root(v)==root(u));
}
void dfs(int v){
    for(auto& i:a[v]){
        if(!dept[i.ff] || dept[i.ff]>dept[v])
            cup[v]--;
        else cup[v]++;
        if(!dept[i.ff]){
            dept[i.ff]=dept[v]+1;
            cpar[i.ff]=i.ss;
            par[i.ff]=v;
            dfs(i.ff);
        }
    }
    cup[par[v]]+=cup[v];
    if(cup[v]>1) merge(v,par[v]);
}
void dfs2(int v,int u){
    dept[v]=dept[u]+1;
    par[v]=u;
    vis[v]=1;
    for(auto& i:g[v]){
        if(i.ff==u) continue;
        cpar[i.ff]=i.ss;
        dfs2(i.ff,v);
    }
}
void solve(){
    pii pi,pj;
    int n,m,o,p,q;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        c[i]='B';
        cin>>p>>q;
        edge[i]={p,q};
        a[p].append({q,i});
        a[q].append({p,i});
    }
    for(int i=1;i<=n;i++){
        if(dept[i]) continue;
        dept[i]=1;
        dfs(i);
    }
    for(int i=2;i<=n;i++){
        if(same(i,par[i])) continue;
        p=root(i);
        q=root(par[i]);
        g[p].append({q,cpar[i]});
        g[q].append({p,cpar[i]});
    }
    for(int i=1;i<=n;i++){
        if(!vis[root(i)])
            dfs2(root(i),0);
    }
    cin>>o;
    while(o--){
        cin>>p>>q;
        p=root(p);
        q=root(q);
        while(p!=q){
            if(dept[p]>dept[q]){
                pj={p,par[p]};
                pi=edge[cpar[p]];
                pi.ff=root(pi.ff);
                pi.ss=root(pi.ss);
                if(pj==pi)
                    c[cpar[p]]='R';
                else c[cpar[p]]='L';
                p=par[p];
            }
            else{
                pj={q,par[q]};
                pi=edge[cpar[q]];
                pi.ff=root(pi.ff);
                pi.ss=root(pi.ss);
                if(pj==pi)
                    c[cpar[q]]='L';
                else c[cpar[q]]='R';
                q=par[q];
            }
        }
    }
    for(int i=0;i<m;i++)
        cout<<c[i];
}
int terminator(){
    L0TA;
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6796 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6800 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6796 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6800 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 26 ms 12112 KB Output is correct
12 Correct 33 ms 13120 KB Output is correct
13 Correct 31 ms 14320 KB Output is correct
14 Correct 34 ms 15852 KB Output is correct
15 Correct 37 ms 16336 KB Output is correct
16 Correct 39 ms 16716 KB Output is correct
17 Correct 64 ms 18004 KB Output is correct
18 Correct 40 ms 16724 KB Output is correct
19 Correct 72 ms 19028 KB Output is correct
20 Correct 26 ms 12880 KB Output is correct
21 Correct 26 ms 12580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6796 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6800 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 26 ms 12112 KB Output is correct
12 Correct 33 ms 13120 KB Output is correct
13 Correct 31 ms 14320 KB Output is correct
14 Correct 34 ms 15852 KB Output is correct
15 Correct 37 ms 16336 KB Output is correct
16 Correct 39 ms 16716 KB Output is correct
17 Correct 64 ms 18004 KB Output is correct
18 Correct 40 ms 16724 KB Output is correct
19 Correct 72 ms 19028 KB Output is correct
20 Correct 26 ms 12880 KB Output is correct
21 Correct 26 ms 12580 KB Output is correct
22 Execution timed out 3056 ms 18212 KB Time limit exceeded
23 Halted 0 ms 0 KB -