답안 #1104775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104775 2024-10-24T11:50:23 Z alexander707070 Simurgh (IOI17_simurgh) C++14
51 / 100
2932 ms 5988 KB
#include<bits/stdc++.h>
#include "simurgh.h"

#define MAXN 507
#define MAXM 300007
using namespace std;
 
int n,m,dep[MAXN];
vector< pair<int,int> > v[MAXN];

bool intree[MAXM],vis[MAXN];

pair<int,int> edge[MAXM],parent[MAXN];

int value[MAXM],st[MAXM],sumtree;
vector<int> ans;

unordered_set<int> s;

int calc(vector<int> rem,vector<int> add){
	for(int i:rem)s.erase(i);
	for(int i:add)s.insert(i);

	vector<int> w;
	for(int i:s){
		w.push_back(i-1);
	}

	for(int i:rem)s.insert(i);
	for(int i:add)s.erase(i);

	return count_common_roads(w);
}

void dfs(int x){
	vis[x]=true;

	for(int i=0;i<v[x].size();i++){
		if(vis[v[x][i].first])continue;

		dep[v[x][i].first]=dep[x]+1;
		parent[v[x][i].first]={x,v[x][i].second};

		dfs(v[x][i].first);

		intree[v[x][i].second]=true;
		s.insert(v[x][i].second);
	}
}

vector<int> path,toask;
int total;

void dfs2(int x){
	vis[x]=true;

	for(int i=0;i<v[x].size();i++){
		if(vis[v[x][i].first] or !intree[v[x][i].second]){
			continue;
		}

		toask.push_back(v[x][i].second-1);
		total-=(value[v[x][i].second]-1);

		dfs2(v[x][i].first);
	}
}

void up(int x,int y){
	if(x==y)return;

	path.push_back(parent[x].second);
	up(parent[x].first,y);
}

int howmany(int root,int l,int r){
	toask.clear();

	for(int i=1;i<=n;i++)vis[i]=false;

	vis[root]=true;
	for(int i=l;i<=r;i++)vis[v[root][i].first]=true;

	for(int i=l;i<=r;i++){
		toask.push_back(v[root][i].second-1);
	}

	total=0;

	dfs2(root);
	for(int i=l;i<=r;i++){
		dfs2(v[root][i].first);
	}

	total+=count_common_roads(toask);

	return total;
}

void solve(int root,int l,int r){
	if(l==r){
		value[v[root][l].second]=2;
		return;
	}

	int mid=(l+r)/2;
	if(howmany(root,l,mid)!=0){
		solve(root,l,mid);
	}

	if(howmany(root,mid+1,r)!=0){
		solve(root,mid+1,r);
	}
}
 
vector<int> find_roads(int N,vector<int> from,vector<int> to){
	n=N; m=int(from.size());

	for(int i=1;i<=m;i++){
		from[i-1]++; to[i-1]++;

		edge[i]={from[i-1],to[i-1]};

		v[from[i-1]].push_back({to[i-1],i});
		v[to[i-1]].push_back({from[i-1],i});
	}

	dfs(1);
	sumtree=calc({},{});

	for(int i=1;i<=m;i++){
		if(intree[i])continue;

		int u=from[i-1],w=to[i-1];
		if(dep[u]>dep[w])swap(u,w);

		path.clear();
		up(w,u);

		int mins=sumtree,maxs=sumtree,br=0,ask=0;

		for(int f:path){
			if(value[f]==0){
				st[f]=calc({f},{i});
				br++;

				mins=min(mins,st[f]);
				maxs=max(maxs,st[f]);
			}
		}

		if(br==0)continue;

		if(mins==maxs){
			for(int f:path){
				if(value[f]==0)continue;

				st[f]=calc({f},{i});
				ask=value[f];
				
				mins=min(mins,st[f]);
				maxs=max(maxs,st[f]);

				break;
			}
		}

		for(int f:path){
			if(value[f]!=0)continue;

			if(mins==maxs)value[f]=ask;
			else{
				if(st[f]==mins)value[f]=2;
				else value[f]=1;
			}
		}
	}
	
	for(int i=1;i<=m;i++){
		if(intree[i] and value[i]==0)value[i]=2;
	}

	for(int i=1;i<=n;i++){
		solve(i,0,v[i].size()-1);
	}

	for(int i=1;i<=m;i++){
		if(value[i]==2){
			ans.push_back(i-1);
		}
	}

	return ans;
}

Compilation message

simurgh.cpp: In function 'void dfs(int)':
simurgh.cpp:38:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for(int i=0;i<v[x].size();i++){
      |              ~^~~~~~~~~~~~
simurgh.cpp: In function 'void dfs2(int)':
simurgh.cpp:57:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for(int i=0;i<v[x].size();i++){
      |              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB correct
2 Correct 1 ms 2384 KB correct
3 Correct 1 ms 2556 KB correct
4 Correct 1 ms 2384 KB correct
5 Correct 1 ms 2384 KB correct
6 Correct 1 ms 2500 KB correct
7 Correct 1 ms 2384 KB correct
8 Correct 1 ms 2384 KB correct
9 Correct 1 ms 2384 KB correct
10 Correct 1 ms 2384 KB correct
11 Correct 1 ms 2384 KB correct
12 Correct 1 ms 2384 KB correct
13 Correct 1 ms 2552 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB correct
2 Correct 1 ms 2384 KB correct
3 Correct 1 ms 2556 KB correct
4 Correct 1 ms 2384 KB correct
5 Correct 1 ms 2384 KB correct
6 Correct 1 ms 2500 KB correct
7 Correct 1 ms 2384 KB correct
8 Correct 1 ms 2384 KB correct
9 Correct 1 ms 2384 KB correct
10 Correct 1 ms 2384 KB correct
11 Correct 1 ms 2384 KB correct
12 Correct 1 ms 2384 KB correct
13 Correct 1 ms 2552 KB correct
14 Correct 10 ms 2384 KB correct
15 Correct 7 ms 2384 KB correct
16 Correct 8 ms 2764 KB correct
17 Correct 8 ms 2384 KB correct
18 Correct 3 ms 2384 KB correct
19 Correct 8 ms 2384 KB correct
20 Correct 7 ms 2384 KB correct
21 Correct 7 ms 2584 KB correct
22 Correct 4 ms 2384 KB correct
23 Correct 3 ms 2384 KB correct
24 Correct 3 ms 2384 KB correct
25 Correct 1 ms 2384 KB correct
26 Correct 3 ms 2384 KB correct
27 Correct 3 ms 2384 KB correct
28 Correct 2 ms 2384 KB correct
29 Correct 1 ms 2384 KB correct
30 Correct 4 ms 2512 KB correct
31 Correct 4 ms 2384 KB correct
32 Correct 4 ms 2384 KB correct
33 Correct 4 ms 2564 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB correct
2 Correct 1 ms 2384 KB correct
3 Correct 1 ms 2556 KB correct
4 Correct 1 ms 2384 KB correct
5 Correct 1 ms 2384 KB correct
6 Correct 1 ms 2500 KB correct
7 Correct 1 ms 2384 KB correct
8 Correct 1 ms 2384 KB correct
9 Correct 1 ms 2384 KB correct
10 Correct 1 ms 2384 KB correct
11 Correct 1 ms 2384 KB correct
12 Correct 1 ms 2384 KB correct
13 Correct 1 ms 2552 KB correct
14 Correct 10 ms 2384 KB correct
15 Correct 7 ms 2384 KB correct
16 Correct 8 ms 2764 KB correct
17 Correct 8 ms 2384 KB correct
18 Correct 3 ms 2384 KB correct
19 Correct 8 ms 2384 KB correct
20 Correct 7 ms 2384 KB correct
21 Correct 7 ms 2584 KB correct
22 Correct 4 ms 2384 KB correct
23 Correct 3 ms 2384 KB correct
24 Correct 3 ms 2384 KB correct
25 Correct 1 ms 2384 KB correct
26 Correct 3 ms 2384 KB correct
27 Correct 3 ms 2384 KB correct
28 Correct 2 ms 2384 KB correct
29 Correct 1 ms 2384 KB correct
30 Correct 4 ms 2512 KB correct
31 Correct 4 ms 2384 KB correct
32 Correct 4 ms 2384 KB correct
33 Correct 4 ms 2564 KB correct
34 Correct 1447 ms 3912 KB correct
35 Correct 1403 ms 3856 KB correct
36 Correct 915 ms 3656 KB correct
37 Correct 28 ms 2384 KB correct
38 Correct 1497 ms 3912 KB correct
39 Correct 1060 ms 3756 KB correct
40 Correct 767 ms 3656 KB correct
41 Correct 940 ms 3908 KB correct
42 Correct 960 ms 3664 KB correct
43 Correct 354 ms 3408 KB correct
44 Correct 229 ms 3152 KB correct
45 Correct 296 ms 3152 KB correct
46 Correct 190 ms 2896 KB correct
47 Correct 59 ms 2640 KB correct
48 Correct 7 ms 2384 KB correct
49 Correct 18 ms 2384 KB correct
50 Correct 58 ms 2820 KB correct
51 Correct 285 ms 3224 KB correct
52 Correct 230 ms 3152 KB correct
53 Correct 180 ms 2896 KB correct
54 Correct 353 ms 3412 KB correct
55 Correct 395 ms 3152 KB correct
56 Correct 413 ms 3204 KB correct
57 Correct 394 ms 3176 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB correct
2 Correct 1 ms 2384 KB correct
3 Incorrect 2932 ms 5988 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB correct
2 Correct 1 ms 2384 KB correct
3 Correct 1 ms 2556 KB correct
4 Correct 1 ms 2384 KB correct
5 Correct 1 ms 2384 KB correct
6 Correct 1 ms 2500 KB correct
7 Correct 1 ms 2384 KB correct
8 Correct 1 ms 2384 KB correct
9 Correct 1 ms 2384 KB correct
10 Correct 1 ms 2384 KB correct
11 Correct 1 ms 2384 KB correct
12 Correct 1 ms 2384 KB correct
13 Correct 1 ms 2552 KB correct
14 Correct 10 ms 2384 KB correct
15 Correct 7 ms 2384 KB correct
16 Correct 8 ms 2764 KB correct
17 Correct 8 ms 2384 KB correct
18 Correct 3 ms 2384 KB correct
19 Correct 8 ms 2384 KB correct
20 Correct 7 ms 2384 KB correct
21 Correct 7 ms 2584 KB correct
22 Correct 4 ms 2384 KB correct
23 Correct 3 ms 2384 KB correct
24 Correct 3 ms 2384 KB correct
25 Correct 1 ms 2384 KB correct
26 Correct 3 ms 2384 KB correct
27 Correct 3 ms 2384 KB correct
28 Correct 2 ms 2384 KB correct
29 Correct 1 ms 2384 KB correct
30 Correct 4 ms 2512 KB correct
31 Correct 4 ms 2384 KB correct
32 Correct 4 ms 2384 KB correct
33 Correct 4 ms 2564 KB correct
34 Correct 1447 ms 3912 KB correct
35 Correct 1403 ms 3856 KB correct
36 Correct 915 ms 3656 KB correct
37 Correct 28 ms 2384 KB correct
38 Correct 1497 ms 3912 KB correct
39 Correct 1060 ms 3756 KB correct
40 Correct 767 ms 3656 KB correct
41 Correct 940 ms 3908 KB correct
42 Correct 960 ms 3664 KB correct
43 Correct 354 ms 3408 KB correct
44 Correct 229 ms 3152 KB correct
45 Correct 296 ms 3152 KB correct
46 Correct 190 ms 2896 KB correct
47 Correct 59 ms 2640 KB correct
48 Correct 7 ms 2384 KB correct
49 Correct 18 ms 2384 KB correct
50 Correct 58 ms 2820 KB correct
51 Correct 285 ms 3224 KB correct
52 Correct 230 ms 3152 KB correct
53 Correct 180 ms 2896 KB correct
54 Correct 353 ms 3412 KB correct
55 Correct 395 ms 3152 KB correct
56 Correct 413 ms 3204 KB correct
57 Correct 394 ms 3176 KB correct
58 Correct 1 ms 2384 KB correct
59 Correct 1 ms 2384 KB correct
60 Incorrect 2932 ms 5988 KB WA in grader: NO
61 Halted 0 ms 0 KB -