이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t) cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
st << "(" << p.first << ", " << p.second << ")";
return st;
}
void tc();
auto test_cases = []() {
int T; scanf("%d", &T);
while(T--) tc();
};
using namespace std;
const int MAXN = 100*1000 + 10;
int dfs_num[MAXN], dfs_low[MAXN], dfs_time;
list<int> E[MAXN];
vi fr, to;
vector<bool> isBridge;
int n, m, p;
void dfs(int u, int ie){
dfs_low[u] = dfs_num[u] = dfs_time++;
for(int e : E[u]) if(e != ie) {
int v = fr[e] + to[e] - u;
if(dfs_num[v] == -1){
dfs(v, e);
if(dfs_low[v] > dfs_num[u]) {
isBridge[e] = true;
}
dfs_low[u] = min(dfs_low[u], dfs_low[v]);
} else {
dfs_low[u] = min(dfs_low[u], dfs_num[v]);
}
}
}
int id[MAXN], W[MAXN];
int find(int a){
return id[a] = (a == id[a]) ? a : find(id[a]);
}
void join(int a, int b){
a = find(a);
b = find(b);
if(a == b) return;
if(W[a] < W[b]) swap(a, b);
W[a] += W[b];
id[b] = a;
E[a].splice(E[a].end(), E[b]);
}
int val[MAXN], depth[MAXN];
vi edgeVal;
int dfs3(int u, int p){
depth[u] = depth[p] + 1;
int ret = val[u];
dfs_num[u] = 1;
for(int e : E[u]) {
int v = find(fr[e]) + find(to[e]) - u;
if(v == p) continue;
int tmp = dfs3(v, u);
edgeVal[e] = tmp;
ret += tmp;
}
return ret;
}
int main(){
#ifdef HOME
freopen("in.in", "r", stdin);
#endif
scanf("%d %d", &n, &m);
loop(e, m){
int a, b; scanf("%d %d", &a, &b);
fr.push_back(a);
to.push_back(b);
isBridge.push_back(false);
E[a].push_back(e);
E[b].push_back(e);
}
memset(dfs_num, -1, sizeof dfs_num);
for(int i = 1; i <= n; i++) if(dfs_num[i] == -1) dfs(i, -1);
fill(W, W + n + 1, 1);
iota(id, id + n + 1, 0);
loop(e, m) if(!isBridge[e]) join(fr[e], to[e]);
vi V;
for(int i = 1; i <= n; i++) if(i == find(i)) V.push_back(i);
list<int> aux;
for(int i : V){
aux.clear();
for(int e : E[i]) if(isBridge[e]){
aux.push_back(e);
}
E[i].swap(aux);
}
edgeVal.resize(m, 0);
scanf("%d", &p);
while(p--){
int a, b; scanf("%d %d", &a, &b);
a = find(a), b = find(b);
if(a == b) continue;
val[a]++;
val[b]--;
}
memset(dfs_num, -1, sizeof dfs_num);
for(int i : V) if(dfs_num[i] == -1) dfs3(i, 0);
loop(e, m) {
if(!isBridge[e] || edgeVal[e] == 0) putchar('B');
else {
int a0 = find(fr[e]), b0 = find(to[e]);
int a = a0, b = b0;
if(depth[a] > depth[b]) swap(a, b);
if(edgeVal[e] > 0) swap(a, b);
putchar("LR"[a == a0]);
}
}
puts("");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
oneway.cpp: In function 'int main()':
oneway.cpp:92:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
92 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:94:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
94 | int a, b; scanf("%d %d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:118:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
118 | scanf("%d", &p);
| ~~~~~^~~~~~~~~~
oneway.cpp:120:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
120 | int a, b; scanf("%d %d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |