답안 #609632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
609632 2022-07-27T18:35:13 Z HamletPetrosyan Jail (JOI22_jail) C++17
컴파일 오류
0 ms 0 KB
	}

	tin[v] = ++timer;
	for(int i = 0; i < len(g[v]); i++){
		int to = g[v][i];
		if(to == p) continue;
		dfs(to, v);
	}
	tout[v] = ++timer;
}

bool isa(int a, int b){
	return (tin[a] <= tin[b] && tout[b] <= tout[a]);
}

int lsa(int a, int b){
	if(isa(a, b)) return a;
	if(isa(b, a)) return b;
	for(int i = 20; i >= 0; i--){
		if(isa(ls[a][i], b)) continue;
		a = ls[a][i];
	}
	return ls[a][0];
}

void check(int i, int j){
	int a = lsa(s[i], t[i]);
	int b = lsa(s[j], t[j]);
	if(isa(a, s[j]) && (isa(s[j], s[i]) || isa(s[j], t[i]))){
		dir[i].add(j);
	}
	if(isa(b, t[i]) && (isa(t[i], s[j]) || isa(t[i], t[j]))){
		dir[i].add(j);
	}
}

bool check_cycle(int v){
	color[v] = 1;
	for(int i = 0; i < len(dir[v]); i++){
		int to = dir[v][i];
		if(color[to] == 2) continue;
		if(color[to] == 1) {
			return true;
		}
		if(check_cycle(to)){
			return true;
		}
	}
	color[v] = 2;
	return false;
}

void solve(){
	timer = 0;

	cin >> n;
	for(int i = 1; i <= n; i++){
		g[i].clear();
	}
	for(int i = 0; i < m; i++){
		dir[i].clear();
		color[i] = 0;
	}

	int u, v;
	for(int i = 1; i < n; i++){
		cin >> u >> v;
		g[u].add(v);
		g[v].add(u);
	}
	dfs(1, 1);
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> s[i] >> t[i];
	}

	for(int i = 0; i < m; i++){
		for(int j = 0; j < m; j++){
			if(i == j) continue;
			check(i, j);
		}
	}
	for(int i = 0; i < m; i++){
		if(color[i] == 0) {
			if(check_cycle(i)){
				cout << "No\n";
				return;
			}
		}
	}

	cout << "Yes\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int _ = 1;
	// cout << fixed;
	// cout.precision(15);

	cin >> _ ;
	while(_--) solve();
	return 0;
}

/// #else
/// #include <bits/stdc++.h> using namespace std; int main() { cout << "Hello World!"; }
/// #endif

Compilation message

jail.cpp:1:2: error: expected declaration before '}' token
    1 |  }
      |  ^
jail.cpp:3:2: error: 'tin' does not name a type
    3 |  tin[v] = ++timer;
      |  ^~~
jail.cpp:4:2: error: expected unqualified-id before 'for'
    4 |  for(int i = 0; i < len(g[v]); i++){
      |  ^~~
jail.cpp:4:17: error: 'i' does not name a type
    4 |  for(int i = 0; i < len(g[v]); i++){
      |                 ^
jail.cpp:4:32: error: 'i' does not name a type
    4 |  for(int i = 0; i < len(g[v]); i++){
      |                                ^
jail.cpp:9:2: error: 'tout' does not name a type
    9 |  tout[v] = ++timer;
      |  ^~~~
jail.cpp:10:1: error: expected declaration before '}' token
   10 | }
      | ^
jail.cpp: In function 'bool isa(int, int)':
jail.cpp:13:10: error: 'tin' was not declared in this scope
   13 |  return (tin[a] <= tin[b] && tout[b] <= tout[a]);
      |          ^~~
jail.cpp:13:30: error: 'tout' was not declared in this scope
   13 |  return (tin[a] <= tin[b] && tout[b] <= tout[a]);
      |                              ^~~~
jail.cpp: In function 'int lsa(int, int)':
jail.cpp:20:10: error: 'ls' was not declared in this scope; did you mean 'lsa'?
   20 |   if(isa(ls[a][i], b)) continue;
      |          ^~
      |          lsa
jail.cpp:21:7: error: 'ls' was not declared in this scope; did you mean 'lsa'?
   21 |   a = ls[a][i];
      |       ^~
      |       lsa
jail.cpp:23:9: error: 'ls' was not declared in this scope; did you mean 'lsa'?
   23 |  return ls[a][0];
      |         ^~
      |         lsa
jail.cpp: In function 'void check(int, int)':
jail.cpp:27:14: error: 's' was not declared in this scope
   27 |  int a = lsa(s[i], t[i]);
      |              ^
jail.cpp:27:20: error: 't' was not declared in this scope
   27 |  int a = lsa(s[i], t[i]);
      |                    ^
jail.cpp:30:3: error: 'dir' was not declared in this scope
   30 |   dir[i].add(j);
      |   ^~~
jail.cpp:33:3: error: 'dir' was not declared in this scope
   33 |   dir[i].add(j);
      |   ^~~
jail.cpp: In function 'bool check_cycle(int)':
jail.cpp:38:2: error: 'color' was not declared in this scope
   38 |  color[v] = 1;
      |  ^~~~~
jail.cpp:39:25: error: 'dir' was not declared in this scope
   39 |  for(int i = 0; i < len(dir[v]); i++){
      |                         ^~~
jail.cpp:39:21: error: 'len' was not declared in this scope
   39 |  for(int i = 0; i < len(dir[v]); i++){
      |                     ^~~
jail.cpp: In function 'void solve()':
jail.cpp:54:2: error: 'timer' was not declared in this scope
   54 |  timer = 0;
      |  ^~~~~
jail.cpp:56:2: error: 'cin' was not declared in this scope
   56 |  cin >> n;
      |  ^~~
jail.cpp:56:9: error: 'n' was not declared in this scope
   56 |  cin >> n;
      |         ^
jail.cpp:58:3: error: 'g' was not declared in this scope
   58 |   g[i].clear();
      |   ^
jail.cpp:60:21: error: 'm' was not declared in this scope
   60 |  for(int i = 0; i < m; i++){
      |                     ^
jail.cpp:61:3: error: 'dir' was not declared in this scope
   61 |   dir[i].clear();
      |   ^~~
jail.cpp:62:3: error: 'color' was not declared in this scope
   62 |   color[i] = 0;
      |   ^~~~~
jail.cpp:68:3: error: 'g' was not declared in this scope
   68 |   g[u].add(v);
      |   ^
jail.cpp:71:2: error: 'dfs' was not declared in this scope
   71 |  dfs(1, 1);
      |  ^~~
jail.cpp:72:9: error: 'm' was not declared in this scope
   72 |  cin >> m;
      |         ^
jail.cpp:74:10: error: 's' was not declared in this scope
   74 |   cin >> s[i] >> t[i];
      |          ^
jail.cpp:74:18: error: 't' was not declared in this scope
   74 |   cin >> s[i] >> t[i];
      |                  ^
jail.cpp:84:6: error: 'color' was not declared in this scope
   84 |   if(color[i] == 0) {
      |      ^~~~~
jail.cpp:86:5: error: 'cout' was not declared in this scope
   86 |     cout << "No\n";
      |     ^~~~
jail.cpp:92:2: error: 'cout' was not declared in this scope
   92 |  cout << "Yes\n";
      |  ^~~~
jail.cpp: In function 'int main()':
jail.cpp:96:2: error: 'ios_base' has not been declared
   96 |  ios_base::sync_with_stdio(false);
      |  ^~~~~~~~
jail.cpp:97:2: error: 'cin' was not declared in this scope
   97 |  cin.tie(0);
      |  ^~~