답안 #1057314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057314 2024-08-13T17:07:36 Z mnbvcxz123 One-Way Streets (CEOI17_oneway) C++17
100 / 100
46 ms 22468 KB
    #include<bits/stdc++.h>
     
    using namespace std;
    int n, m, p, u, v, lead[100005], low[100005], num[100005], d = 0, cnt = 0, ans[100005], timer = 0, q, val[100005];
    vector<pair<int,int>> adj[100005];
    vector<pair<int,int>> adj2[100005], edge;
    stack<int> s;
    bool mark[100005];
    void dfs(int u, int id) {
    	low[u] = num[u] = ++d;
    	s.push(u);
    	for (pair<int, int> W: adj[u]) {
    		int node = W.first;
    		if(W.second == id) continue;
    		if(num[node] != 0) low[u] = min(low[u], num[node]);
    		else {
    			dfs(node, W.second);
    			low[u] = min(low[u], low[node]);
    		}
    	}
    	if(low[u] == num[u]) {
    		cnt++;
    		while(s.top() != u) lead[s.top()] = cnt, s.pop();
    		lead[s.top()] = cnt, s.pop();
    	}
    }
    void cal(int u, int par) {
    	for (pair<int, int> node: adj2[u]) {
    		if(mark[node.first]) continue;
    		mark[node.first] = true;
    		cal(node.first, u);
    		val[u] += val[node.first];
    	}
    }
    void get_ans(int u, int par) {
    	for (pair<int, int> node: adj2[u]) {
    		if(mark[node.first]) continue;
    		mark[node.first] = true;
    		int x, y;
    		x = u, y = node.first;
    		int id = node.second;
    		//cout << "QWFQWF " << x << ' ' << y  << ' ' << id << '\n';
    		if(val[node.first] < 0) {
    			//cout << "EDGE " << x << ' ' << y << ' ' << edge[id].first << ' ' << edge[id].second << '\n';
    			if(lead[edge[id].first] == x && lead[edge[id].second] == y) ans[id+1] = 1;
    			else ans[id+1] = 2;
    		}
    		else if(val[node.first] > 0) {
    			//cout << "EDGE " << x << ' ' << y << ' ' << edge[id].first << ' ' << edge[id].second << '\n';
    			if(lead[edge[id].first] == x && lead[edge[id].second] == y) ans[id+1] = 2;
    			else ans[id+1] = 1;
    		}
    		else ans[id+1] = 0;
    		get_ans(node.first, u);
    	}
    }
    void solve() {
    	cin >> n >> m;
    	for (int i = 1; i <= m; i++) {
    		cin >> u >> v;
    		edge.push_back({u,v});
    		adj[u].push_back({v,i});
    		adj[v].push_back({u,i});
    	}
    	for (int i = 1; i <= n; i++) {
    		if(num[i] == 0) dfs(i, -1);
    	}
    	int idx = 0;
    	for (pair<int, int> i: edge) {
    		if(lead[i.first] != lead[i.second]) adj2[lead[i.first]].push_back({lead[i.second], idx}), adj2[lead[i.second]].push_back({lead[i.first],idx});
    		idx++;
    	}
    	cin >> q;
    	while(q--) {
    		cin >> u >> v;
    		u = lead[u];
    		v = lead[v];
    		val[u]++;
    		val[v]--;
    	}
    	for (int i = 1; i <= cnt; i++) if(!mark[i]) cal(i,-1);
    	memset(mark, 0, sizeof(mark));
    	for (int i = 1; i <= cnt; i++) if(!mark[i]) get_ans(i, -1);
    	for (int i = 1; i <= m; i++) if(ans[i] == 0) cout << 'B'; else if(ans[i] == 1) cout << 'R'; else cout << 'L';
    }
     
    signed main() {
    	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    	if(fopen("input.inp","r")){
    		freopen("input.inp", "r", stdin);
    		freopen("output.out", "w", stdout);
    	}
    	int t = 1;
    	// cin >> t;
    	while(t--) {
    		solve();
    	}
    }

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:90:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |       freopen("input.inp", "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:91:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |       freopen("output.out", "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6744 KB Output is correct
9 Correct 1 ms 6704 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6744 KB Output is correct
9 Correct 1 ms 6704 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 21 ms 12740 KB Output is correct
12 Correct 22 ms 13508 KB Output is correct
13 Correct 23 ms 14592 KB Output is correct
14 Correct 30 ms 15304 KB Output is correct
15 Correct 27 ms 15812 KB Output is correct
16 Correct 37 ms 16584 KB Output is correct
17 Correct 33 ms 17864 KB Output is correct
18 Correct 32 ms 16692 KB Output is correct
19 Correct 29 ms 19404 KB Output is correct
20 Correct 20 ms 13000 KB Output is correct
21 Correct 21 ms 12884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6744 KB Output is correct
9 Correct 1 ms 6704 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 21 ms 12740 KB Output is correct
12 Correct 22 ms 13508 KB Output is correct
13 Correct 23 ms 14592 KB Output is correct
14 Correct 30 ms 15304 KB Output is correct
15 Correct 27 ms 15812 KB Output is correct
16 Correct 37 ms 16584 KB Output is correct
17 Correct 33 ms 17864 KB Output is correct
18 Correct 32 ms 16692 KB Output is correct
19 Correct 29 ms 19404 KB Output is correct
20 Correct 20 ms 13000 KB Output is correct
21 Correct 21 ms 12884 KB Output is correct
22 Correct 41 ms 19144 KB Output is correct
23 Correct 43 ms 17604 KB Output is correct
24 Correct 46 ms 17688 KB Output is correct
25 Correct 42 ms 22468 KB Output is correct
26 Correct 39 ms 18884 KB Output is correct
27 Correct 41 ms 17672 KB Output is correct
28 Correct 17 ms 10704 KB Output is correct
29 Correct 29 ms 13764 KB Output is correct
30 Correct 27 ms 14032 KB Output is correct
31 Correct 29 ms 14420 KB Output is correct
32 Correct 32 ms 16840 KB Output is correct