답안 #1027345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027345 2024-07-19T03:52:05 Z ara_ara One-Way Streets (CEOI17_oneway) C++17
100 / 100
67 ms 30036 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+5;
vector<pair<int,int>> adj[maxn],tree[maxn];
pair<int,int> edge[maxn];
int n,m,p;
char res[maxn];
int low[maxn],num[maxn],stt[maxn],del[maxn],cc,timedfs;
int a[maxn],b[maxn];
stack<int> st;
void dfs1(int u,int p){
    num[u]=low[u]=++timedfs;
    st.push(u);
    bool skip=false;
    for(auto i:adj[u]){
        int v=i.first;
        if(v==p && !skip){
            skip=true;
            continue;
        }
        if(!num[v]){
            dfs1(v,u);
            low[u]=min(low[u],low[v]);
        }
        else low[u]=min(low[u],num[v]);
    }
    if(low[u]==num[u]){
        cc++;
        int v;
        do{
            v=st.top();
            st.pop();
            stt[v]=cc;
            del[v]=true;
        }
        while(v!=u);
    }
}
int vis[maxn];
vector<int> dir[maxn]; 
void dfs2(int u,int idx){
    vis[u]=1;
    for(auto i:tree[u])if(!vis[i.first]){
        dfs2(i.first,i.second);
        a[u]+=a[i.first];
        b[u]+=b[i.first];
    }
    if(a[u]==b[u]) res[idx]='B';
    else if(a[u]>b[u]){
        if(stt[edge[idx].first]==u) res[idx]='R';
        else res[idx]='L';
    }
    else{
        if(stt[edge[idx].first]==u) res[idx]='L';
        else res[idx]='R';
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        edge[i]={u,v};
        adj[u].push_back({v,i});
        adj[v].push_back({u,i});
    }
    for(int i=1;i<=n;i++) if(!del[i]) dfs1(i,i);
    for(int u=1;u<=n;u++)
        for(auto i:adj[u])
            if(stt[u]!=stt[i.first]) tree[stt[u]].push_back({stt[i.first],i.second});
    cin>>p;
    for(int i=1;i<=p;i++){
        int u,v;
        cin>>u>>v;
        if(stt[u]==stt[v]) continue;
        a[stt[u]]++;
        b[stt[v]]++;
    }
    for(int i=1;i<=cc;i++) if(!vis[i]) dfs2(i,0);
    for(int i=1;i<=m;i++){
        if(!res[i]) cout<<'B';
        else cout<<res[i];
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 2 ms 12592 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 3 ms 12636 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 2 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 2 ms 12592 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 3 ms 12636 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 2 ms 12636 KB Output is correct
11 Correct 30 ms 19544 KB Output is correct
12 Correct 33 ms 20384 KB Output is correct
13 Correct 32 ms 21408 KB Output is correct
14 Correct 39 ms 22100 KB Output is correct
15 Correct 36 ms 22676 KB Output is correct
16 Correct 56 ms 24884 KB Output is correct
17 Correct 45 ms 26460 KB Output is correct
18 Correct 43 ms 24916 KB Output is correct
19 Correct 41 ms 27728 KB Output is correct
20 Correct 30 ms 19712 KB Output is correct
21 Correct 27 ms 19540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB Output is correct
2 Correct 2 ms 12380 KB Output is correct
3 Correct 2 ms 12592 KB Output is correct
4 Correct 2 ms 12636 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 3 ms 12636 KB Output is correct
7 Correct 2 ms 12636 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 2 ms 12636 KB Output is correct
11 Correct 30 ms 19544 KB Output is correct
12 Correct 33 ms 20384 KB Output is correct
13 Correct 32 ms 21408 KB Output is correct
14 Correct 39 ms 22100 KB Output is correct
15 Correct 36 ms 22676 KB Output is correct
16 Correct 56 ms 24884 KB Output is correct
17 Correct 45 ms 26460 KB Output is correct
18 Correct 43 ms 24916 KB Output is correct
19 Correct 41 ms 27728 KB Output is correct
20 Correct 30 ms 19712 KB Output is correct
21 Correct 27 ms 19540 KB Output is correct
22 Correct 66 ms 26452 KB Output is correct
23 Correct 67 ms 24868 KB Output is correct
24 Correct 62 ms 24912 KB Output is correct
25 Correct 64 ms 30036 KB Output is correct
26 Correct 56 ms 26160 KB Output is correct
27 Correct 60 ms 24912 KB Output is correct
28 Correct 21 ms 16732 KB Output is correct
29 Correct 39 ms 19340 KB Output is correct
30 Correct 37 ms 19540 KB Output is correct
31 Correct 38 ms 19792 KB Output is correct
32 Correct 45 ms 22840 KB Output is correct