답안 #285601

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285601 2020-08-29T10:16:03 Z mohammad Simurgh (IOI17_simurgh) C++14
51 / 100
339 ms 13800 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) {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	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 || roy[{u[i] , v[i]}]) 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 ;
		int de = 0;
		while(dp[y] && mx <= common){
			vector<int> r1 = r ;
			if(dp[y] == dp[x]){
				if(x == y) break;
				if(roy[{x , p[x]}] == 2 && !de){
					r1[mp[{x , p[x]}]] = i;
					int z = count_common_roads(r1);
					if(z == common) {
						de = 2;
						roy[{u[i] , v[i]}] = 2;
						roy[{v[i] , u[i]}] = 2;
						break;
					}else{
						de = 1;
						mx = common + 1;
						r2 = r1;
						break;
					}
				}
				x = p[x];
			}else if(dp[y] > dp[x]){
				if(roy[{y , p[y]}] == 2 && !de){
					r1[mp[{y , p[y]}]] = i;
					int z = count_common_roads(r1);
					if(z == common) {
						de = 2;
						roy[{u[i] , v[i]}] = 2;
						roy[{v[i] , u[i]}] = 2;
						break;
					}else{
						de = 1;
						mx = common + 1;
						r2 = r1;
						break;
					}
				}
				y = p[y];
			}
		}
		// cout << "1=-=--=-=-" << endl;
		x = u[i] , y = v[i];
		while(dp[y] && mx <= common && !de){
			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){
						roy[{x , p[x]}] = 2,roy[{p[x] , x}] = 2;
						mx = z;
						r2 = r1;
						break; 
					}
				}
				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);
					pz.push_back(z);
					if(z < common) {
						roy[{y , p[y]}] = 1,roy[{p[y] , y}] = 1;
						break;
					}
					if(mx < z){
						roy[{y , p[y]}] = 2,roy[{p[y] , y}] = 2;
						mx = z;
						r2 = r1;
						break;
					}
				}
				y = p[y];
			}
		}
		if(mx > common){
			x = u[i] , y = v[i];
			int idx = 0;
			while(dp[y] && !de){
				if(dp[y] == dp[x]){
					if(x == y) break;
					if(!roy[{x , p[x]}]){
						if(pz[idx] < common)break;
						else if(common < pz[idx]) break; 
						else roy[{x , p[x]}] = 1;
						idx++;
					}
					x = p[x];
				}else if(dp[y] > dp[x]){
					if(!roy[{y , p[y]}]){
						if(pz[idx] < common)break;
						else if(common < pz[idx]) break; 
						else roy[{y , p[y]}] = 1;
						idx++;
					}
					y = p[y];
				}
			}
			roy[{u[i] , v[i]}] = 1;
			roy[{v[i] , u[i]}] = 1;
			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 ;
		}else{
			x = u[i] , y = v[i];
			int idx = 0;
			while(dp[y] && !de){
				if(dp[y] == dp[x]){
					if(x == y) break;
					if(!roy[{x , p[x]}]){
						if(pz[idx] < common)break;
						else if(common < pz[idx]) break; 
						else roy[{x , p[x]}] = 2;
						idx++;
					}
					x = p[x];
				}else if(dp[y] > dp[x]){
					if(!roy[{y , p[y]}]){
						if(pz[idx] < common)break;
						else if(common < pz[idx]) break; 
						else roy[{y , p[y]}] = 2;
						idx++;
					}
					y = p[y];
				}
			}
		}
	}
	return r;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 0 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 0 ms 384 KB correct
8 Correct 1 ms 384 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 1 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 0 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 0 ms 384 KB correct
8 Correct 1 ms 384 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 5 ms 640 KB correct
15 Correct 4 ms 640 KB correct
16 Correct 4 ms 640 KB correct
17 Correct 5 ms 656 KB correct
18 Correct 3 ms 512 KB correct
19 Correct 4 ms 640 KB correct
20 Correct 4 ms 640 KB correct
21 Correct 4 ms 640 KB correct
22 Correct 1 ms 512 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 388 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 1 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 0 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 0 ms 384 KB correct
8 Correct 1 ms 384 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 5 ms 640 KB correct
15 Correct 4 ms 640 KB correct
16 Correct 4 ms 640 KB correct
17 Correct 5 ms 656 KB correct
18 Correct 3 ms 512 KB correct
19 Correct 4 ms 640 KB correct
20 Correct 4 ms 640 KB correct
21 Correct 4 ms 640 KB correct
22 Correct 1 ms 512 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 388 KB correct
32 Correct 1 ms 384 KB correct
33 Correct 1 ms 384 KB correct
34 Correct 301 ms 7928 KB correct
35 Correct 339 ms 7992 KB correct
36 Correct 209 ms 5496 KB correct
37 Correct 18 ms 640 KB correct
38 Correct 311 ms 8236 KB correct
39 Correct 247 ms 6904 KB correct
40 Correct 192 ms 5460 KB correct
41 Correct 248 ms 7544 KB correct
42 Correct 241 ms 7544 KB correct
43 Correct 15 ms 2560 KB correct
44 Correct 14 ms 2224 KB correct
45 Correct 15 ms 2432 KB correct
46 Correct 10 ms 1920 KB correct
47 Correct 5 ms 1024 KB correct
48 Correct 1 ms 384 KB correct
49 Correct 2 ms 512 KB correct
50 Correct 5 ms 1024 KB correct
51 Correct 14 ms 2432 KB correct
52 Correct 12 ms 2176 KB correct
53 Correct 10 ms 1920 KB correct
54 Correct 16 ms 2560 KB correct
55 Correct 14 ms 2432 KB correct
56 Correct 14 ms 2432 KB correct
57 Correct 15 ms 2560 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Incorrect 279 ms 13800 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 0 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 0 ms 384 KB correct
8 Correct 1 ms 384 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 5 ms 640 KB correct
15 Correct 4 ms 640 KB correct
16 Correct 4 ms 640 KB correct
17 Correct 5 ms 656 KB correct
18 Correct 3 ms 512 KB correct
19 Correct 4 ms 640 KB correct
20 Correct 4 ms 640 KB correct
21 Correct 4 ms 640 KB correct
22 Correct 1 ms 512 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 388 KB correct
32 Correct 1 ms 384 KB correct
33 Correct 1 ms 384 KB correct
34 Correct 301 ms 7928 KB correct
35 Correct 339 ms 7992 KB correct
36 Correct 209 ms 5496 KB correct
37 Correct 18 ms 640 KB correct
38 Correct 311 ms 8236 KB correct
39 Correct 247 ms 6904 KB correct
40 Correct 192 ms 5460 KB correct
41 Correct 248 ms 7544 KB correct
42 Correct 241 ms 7544 KB correct
43 Correct 15 ms 2560 KB correct
44 Correct 14 ms 2224 KB correct
45 Correct 15 ms 2432 KB correct
46 Correct 10 ms 1920 KB correct
47 Correct 5 ms 1024 KB correct
48 Correct 1 ms 384 KB correct
49 Correct 2 ms 512 KB correct
50 Correct 5 ms 1024 KB correct
51 Correct 14 ms 2432 KB correct
52 Correct 12 ms 2176 KB correct
53 Correct 10 ms 1920 KB correct
54 Correct 16 ms 2560 KB correct
55 Correct 14 ms 2432 KB correct
56 Correct 14 ms 2432 KB correct
57 Correct 15 ms 2560 KB correct
58 Correct 1 ms 384 KB correct
59 Correct 1 ms 384 KB correct
60 Incorrect 279 ms 13800 KB WA in grader: NO
61 Halted 0 ms 0 KB -