답안 #285479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285479 2020-08-29T06:56:53 Z mohammad Simurgh (IOI17_simurgh) C++14
30 / 100
238 ms 12152 KB
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
 
#define endl "\n"
// #define int long long

typedef long long ll ;
const ll ooo = 1e14 ;
const ll oo = 2e9 ;
const double PI = acos(-1) ;
const ll M = 1e9 + 7  ;
const int N = 10000010  ;

vector<pair<int , int>> g[501];
vector<int> r , ans , p(501) , dp(501 , 0);
int sz = 0 ;
map<pair<int,int> , int>mp , roy;
int root[501];

ll find(int u){
	if(root[u] == u)
		return u ;
	return root[u] = find(root[u]);
}

void dfs(int u){
	if(p[u] + 1)dp[u] = dp[p[u]] + 1;
	for(auto v : g[u])
		if(v.first != p[u]){
			mp[{u , v.first}] = r.size();
			mp[{v.first , u}] = r.size();
			p[v.first] = u;
			r.push_back(v.second);
			dfs(v.first);
		}
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	for(int i = 0 ; i < n ; ++i) root[i] = i ;
	sz = n;
	int m = u.size();
	for(int i = 0 ; i < m ; ++i){
		if(find(u[i]) != find(v[i])){
			root[find(v[i])] = find(u[i]);
			g[u[i]].push_back({v[i] , i});
			g[v[i]].push_back({u[i] , i});
		}
		mp[{u[i] , v[i]}] = -1;
		mp[{v[i] , u[i]}] = -1;
	}
	dp[0] = 0;
	dfs(0);
	int common = count_common_roads(r);
	for(int i = 0 ; i < m && common != n - 1; ++i){
		if(mp[{u[i] , v[i]}] != -1) continue ;
		if(dp[u[i]] > dp[v[i]]) swap(u[i] , v[i]);
		int x = u[i] , y = v[i];
		vector<int> r2 , pz ;
		int mx = common ;
		// cout << i << ' ' << mx << ' '; 
		while(dp[y] && mx <= common){
			vector<int> r1 = r ;
			if(dp[y] == dp[x]){
				if(x == y) break;
				if(!roy[{x , p[x]}]){
					r1[mp[{x , p[x]}]] = i;
					int z = count_common_roads(r1);
					pz.push_back(z);
					if(z < common) {
						roy[{x , p[x]}] = 1,roy[{p[x] , x}] = 1;
						break;
					}
					if(mx < z){
						mx = z;
						r2 = r1;
					}
				}
				x = p[x];
			}else if(dp[y] > dp[x]){
				if(!roy[{y , p[y]}]){
					r1[mp[{y , p[y]}]] = i;
					int z = count_common_roads(r1);
					if(z < common){
					 	roy[{y , p[y]}] = 1,roy[{p[y] , y}] = 1;
						break;
					}
					pz.push_back(z);
					if(mx < z){
						mx = z;
						r2 = r1;
					}
				}
				y = p[y];
			}
		}
		// cout << mx << endl;
		if(mx > common){
			// cout << i << endl;
			roy[{u[i] , v[i]}] = 1;
			roy[{v[i] , u[i]}] = 1;
			// int x = u[i] , y = v[i] , idx = 0;
			// while(dp[y]){
			// 	if(dp[y] == dp[x]){
			// 		if(x == y) break;
			// 		if(!roy[{x , p[x]}]){
			// 			cout << pz[idx] << ' ' << x << ' ' << p[x] << endl;
			// 			if(pz[idx++] > common) roy[{x , p[x]}] = 1,roy[{p[x] , x}] = 1;
			// 		}
			// 		x = p[x];
			// 	}else if(dp[y] > dp[x]){
			// 		if(!roy[{y , p[y]}]){
			// 			cout << pz[idx] << ' ' << y << ' ' << p[y] << endl;
			// 			if(pz[idx++] > common) roy[{y , p[y]}] = 1,roy[{p[y] , y}] = 1;
			// 		}
			// 		y = p[y];
			// 	}
			// }
			for(int i = 0 ; i < n; ++i) g[i].clear() , p[i] = 0;
			for(auto x: r2){
				g[u[x]].push_back({v[x] , x});
				g[v[x]].push_back({u[x] , x});
			}
			r.clear();
			dp[0] = 0;
			dfs(0);
			common = mx ;
		}
	}
	return r;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 0 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 288 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 0 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 288 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 8 ms 512 KB correct
15 Correct 5 ms 512 KB correct
16 Correct 6 ms 520 KB correct
17 Correct 7 ms 512 KB correct
18 Correct 2 ms 384 KB correct
19 Correct 6 ms 512 KB correct
20 Correct 5 ms 512 KB correct
21 Correct 5 ms 512 KB correct
22 Correct 1 ms 384 KB correct
23 Correct 1 ms 384 KB correct
24 Correct 1 ms 384 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 1 ms 384 KB correct
27 Correct 1 ms 384 KB correct
28 Correct 1 ms 384 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 1 ms 384 KB correct
31 Correct 1 ms 384 KB correct
32 Correct 1 ms 384 KB correct
33 Correct 1 ms 384 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 0 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 288 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 8 ms 512 KB correct
15 Correct 5 ms 512 KB correct
16 Correct 6 ms 520 KB correct
17 Correct 7 ms 512 KB correct
18 Correct 2 ms 384 KB correct
19 Correct 6 ms 512 KB correct
20 Correct 5 ms 512 KB correct
21 Correct 5 ms 512 KB correct
22 Correct 1 ms 384 KB correct
23 Correct 1 ms 384 KB correct
24 Correct 1 ms 384 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 1 ms 384 KB correct
27 Correct 1 ms 384 KB correct
28 Correct 1 ms 384 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 1 ms 384 KB correct
31 Correct 1 ms 384 KB correct
32 Correct 1 ms 384 KB correct
33 Correct 1 ms 384 KB correct
34 Incorrect 197 ms 4600 KB WA in grader: NO
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Incorrect 238 ms 12152 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 0 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 288 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 8 ms 512 KB correct
15 Correct 5 ms 512 KB correct
16 Correct 6 ms 520 KB correct
17 Correct 7 ms 512 KB correct
18 Correct 2 ms 384 KB correct
19 Correct 6 ms 512 KB correct
20 Correct 5 ms 512 KB correct
21 Correct 5 ms 512 KB correct
22 Correct 1 ms 384 KB correct
23 Correct 1 ms 384 KB correct
24 Correct 1 ms 384 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 1 ms 384 KB correct
27 Correct 1 ms 384 KB correct
28 Correct 1 ms 384 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 1 ms 384 KB correct
31 Correct 1 ms 384 KB correct
32 Correct 1 ms 384 KB correct
33 Correct 1 ms 384 KB correct
34 Incorrect 197 ms 4600 KB WA in grader: NO
35 Halted 0 ms 0 KB -