답안 #488450

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
488450 2021-11-19T01:03:39 Z SirCovidThe19th One-Way Streets (CEOI17_oneway) C++17
100 / 100
157 ms 13304 KB
#include <bits/stdc++.h>
using namespace std;

const int mx = 1e5 + 5;

int n, m, q, l[mx], r[mx], tin[mx], ti, in[mx], active[mx], actQry[mx], ans[mx]; 
vector<pair<int, int>> adj[mx]; 

void dfs(int cur, int pedge){
    tin[cur] = ++ti;
	for (int i = 0; i < adj[cur].size(); i++){
		int nxt, id; tie(nxt, id) = adj[cur][i];
		if (id == pedge or tin[nxt] > tin[cur]) continue; //cant go to descendent or use par edg
		if (!tin[nxt]){
            dfs(nxt, id); 
            active[cur] += active[nxt]; 
			actQry[cur] += actQry[nxt];
            if (!active[nxt]){ 
                int curL = (cur == l[id]) ? -1 : 1; 
                int dir = !actQry[nxt] ? 0 : (actQry[nxt] < 0 ? -1 : 1); //-1 up, 1 down
                ans[id] = curL * dir; 
            }
        }
        else in[nxt]++, active[cur]++;
	}
    active[cur] -= in[cur];
}

int main(){
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        int a, b; cin >> a >> b; 
        l[i] = a; r[i] = b;
        adj[a].push_back({b, i}); adj[b].push_back({a, i});
    }
    cin >> q;
    for (int i = 1; i <= q; i++){
        int a, b; cin >> a >> b;
        actQry[a]++; actQry[b]--;
    }
    for (int i = 1; i <= n; i++) if (!tin[i]) dfs(i, 0);
    for (int i = 1; i <= m; i++) cout<<(!ans[i] ? "B" : (ans[i] == -1 ? "L" : "R"));
}

Compilation message

oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:11:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for (int i = 0; i < adj[cur].size(); i++){
      |                  ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 62 ms 7740 KB Output is correct
12 Correct 69 ms 9000 KB Output is correct
13 Correct 85 ms 10076 KB Output is correct
14 Correct 82 ms 10820 KB Output is correct
15 Correct 86 ms 10992 KB Output is correct
16 Correct 90 ms 8900 KB Output is correct
17 Correct 77 ms 10320 KB Output is correct
18 Correct 80 ms 8716 KB Output is correct
19 Correct 76 ms 11424 KB Output is correct
20 Correct 78 ms 8260 KB Output is correct
21 Correct 69 ms 8356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 62 ms 7740 KB Output is correct
12 Correct 69 ms 9000 KB Output is correct
13 Correct 85 ms 10076 KB Output is correct
14 Correct 82 ms 10820 KB Output is correct
15 Correct 86 ms 10992 KB Output is correct
16 Correct 90 ms 8900 KB Output is correct
17 Correct 77 ms 10320 KB Output is correct
18 Correct 80 ms 8716 KB Output is correct
19 Correct 76 ms 11424 KB Output is correct
20 Correct 78 ms 8260 KB Output is correct
21 Correct 69 ms 8356 KB Output is correct
22 Correct 125 ms 10240 KB Output is correct
23 Correct 135 ms 8760 KB Output is correct
24 Correct 139 ms 8828 KB Output is correct
25 Correct 122 ms 13304 KB Output is correct
26 Correct 124 ms 9932 KB Output is correct
27 Correct 157 ms 8816 KB Output is correct
28 Correct 67 ms 5576 KB Output is correct
29 Correct 119 ms 7964 KB Output is correct
30 Correct 121 ms 8248 KB Output is correct
31 Correct 133 ms 8316 KB Output is correct
32 Correct 120 ms 10688 KB Output is correct