Submission #285129

# Submission time Handle Problem Language Result Execution time Memory
285129 2020-08-28T10:44:35 Z mohammad Simurgh (IOI17_simurgh) C++14
30 / 100
253 ms 12336 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;
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 ;
		int mx = common ;
		while(dp[y]){
			vector<int> r1 = r ;
			if(dp[y] == dp[x]){
				if(x == y) break;
				r1[mp[{x , p[x]}]] = i;
				int z = count_common_roads(r1);
				if(mx < z){
					mx = z;
					r2 = r1;
				}
				x = p[x];
			}else if(dp[y] > dp[x]){
				r1[mp[{y , p[y]}]] = i;
				int z = count_common_roads(r1);
				if(mx < z){
					mx = z;
					r2 = r1;
				}
				y = p[y];
			}else break;
		}
		if(mx > common){
			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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 1 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 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 388 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 1 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 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 388 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 12 ms 512 KB correct
15 Correct 7 ms 512 KB correct
16 Correct 7 ms 512 KB correct
17 Correct 11 ms 512 KB correct
18 Correct 5 ms 384 KB correct
19 Correct 10 ms 512 KB correct
20 Correct 7 ms 512 KB correct
21 Correct 8 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 512 KB correct
33 Correct 1 ms 384 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 1 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 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 388 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 12 ms 512 KB correct
15 Correct 7 ms 512 KB correct
16 Correct 7 ms 512 KB correct
17 Correct 11 ms 512 KB correct
18 Correct 5 ms 384 KB correct
19 Correct 10 ms 512 KB correct
20 Correct 7 ms 512 KB correct
21 Correct 8 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 512 KB correct
33 Correct 1 ms 384 KB correct
34 Incorrect 197 ms 4624 KB WA in grader: NO
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Incorrect 253 ms 12336 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB correct
2 Correct 0 ms 384 KB correct
3 Correct 1 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 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 388 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 12 ms 512 KB correct
15 Correct 7 ms 512 KB correct
16 Correct 7 ms 512 KB correct
17 Correct 11 ms 512 KB correct
18 Correct 5 ms 384 KB correct
19 Correct 10 ms 512 KB correct
20 Correct 7 ms 512 KB correct
21 Correct 8 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 512 KB correct
33 Correct 1 ms 384 KB correct
34 Incorrect 197 ms 4624 KB WA in grader: NO
35 Halted 0 ms 0 KB -