답안 #282521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282521 2020-08-24T13:55:59 Z Noam13 Simurgh (IOI17_simurgh) C++14
51 / 100
152 ms 4100 KB
#include "simurgh.h"
#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define ii pair<int, int>
#define x first
#define y second
#define vii vector<ii>
#define vvii vector<vii>
#define pb push_back
#define all(x) x.begin(), x.end()
#define loop(i,s,e) for(int i=s;i<e;++i)
#define chkmax(a,b) a = max(a,b)
#define chkmin(a,b) a = min(a,b)
using namespace std;

int n, m;
vvii g;
vi check;
vi base;
void dfs(int cur, int c){
	check[cur] = c;
	for(auto nei:g[cur]){
		if (check[nei.x]!=0) continue;
		base.pb(nei.y);
		dfs(nei.x, c);
	}
}
int ask(vi& vec){
	//cout<<"QUERY: "<<endl;
	//for(auto x:vec) cout<<x<<" ";
	int v = count_common_roads(vec);
	//cout<<" =" <<v<<endl;
	return v;
}
vi find_roads(int nn, vi u, vi v) {
	n = nn, m = u.size();
	g.resize(n); check.resize(n);
	loop(i,0,m){
		int a = u[i], b = v[i];
		g[a].pb({b,i});
		g[b].pb({a,i});
	}
	queue<int> q; 
	q.push(0); check[0] = -1;
	vi res;
	while(res.size()<n-1){
		int cur = q.front(); q.pop();
		base = res;
		loop(i,0,n) if(check[i]>=0) check[i] = 0;
		int c = 1;
		loop(i,0,n) if(check[i]==0){
			dfs(i, c++);
		}
		loop(i,0,n) if(check[i]>=0) check[i]--;
		c--;
		vvii buckets(c);
		loop(cur, 0, n) if (check[cur]==-1){
			for(auto nei:g[cur]) if(check[nei.x]>=0){
				buckets[check[nei.x]].pb({nei.y, nei.x});
			}
		}
		loop(i,0,n) if (check[i]==-1) check[i]=-2;
		loop(i,0,c){
			vi vec = base;
			loop(j,0,c) if(j!=i)  vec.pb(buckets[j][0].x);
			int m = buckets[i].size();
			vi vals(m);
			int mx = -1;
			loop(j,0,m){
				vec.pb(buckets[i][j].x);
				vals[j] = ask(vec);
				chkmax(mx, vals[j]);
				vec.pop_back();
			}
			loop(j,0,m){
				if (vals[j]==mx){ //golden road
					ii tmp = buckets[i][j];
					res.pb(tmp.x);
					//q.push(tmp.y);
					check[tmp.y] = -1;
				}
			}
		}
	}
	/*for(auto x:res) cout<<x<<" ";
	cout<<endl;*/
	return res;
}
/*
clear
g++ simurgh.cpp grader.cpp -o a ; ./a
4 6
0 1
0 2
0 3
1 2
1 3
2 3
5 1 0

*/

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:49:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |  while(res.size()<n-1){
      |        ~~~~~~~~~~^~~~
simurgh.cpp:50:7: warning: unused variable 'cur' [-Wunused-variable]
   50 |   int cur = q.front(); q.pop();
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 0 ms 256 KB correct
4 Correct 1 ms 256 KB correct
5 Correct 0 ms 256 KB correct
6 Correct 1 ms 512 KB correct
7 Correct 0 ms 256 KB correct
8 Correct 1 ms 256 KB correct
9 Correct 1 ms 256 KB correct
10 Correct 0 ms 256 KB correct
11 Correct 1 ms 256 KB correct
12 Correct 1 ms 256 KB correct
13 Correct 1 ms 256 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 0 ms 256 KB correct
4 Correct 1 ms 256 KB correct
5 Correct 0 ms 256 KB correct
6 Correct 1 ms 512 KB correct
7 Correct 0 ms 256 KB correct
8 Correct 1 ms 256 KB correct
9 Correct 1 ms 256 KB correct
10 Correct 0 ms 256 KB correct
11 Correct 1 ms 256 KB correct
12 Correct 1 ms 256 KB correct
13 Correct 1 ms 256 KB correct
14 Correct 2 ms 384 KB correct
15 Correct 1 ms 384 KB correct
16 Correct 1 ms 384 KB correct
17 Correct 2 ms 384 KB correct
18 Correct 1 ms 384 KB correct
19 Correct 2 ms 384 KB correct
20 Correct 2 ms 384 KB correct
21 Correct 2 ms 384 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 256 KB correct
26 Correct 2 ms 384 KB correct
27 Correct 2 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 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 0 ms 256 KB correct
4 Correct 1 ms 256 KB correct
5 Correct 0 ms 256 KB correct
6 Correct 1 ms 512 KB correct
7 Correct 0 ms 256 KB correct
8 Correct 1 ms 256 KB correct
9 Correct 1 ms 256 KB correct
10 Correct 0 ms 256 KB correct
11 Correct 1 ms 256 KB correct
12 Correct 1 ms 256 KB correct
13 Correct 1 ms 256 KB correct
14 Correct 2 ms 384 KB correct
15 Correct 1 ms 384 KB correct
16 Correct 1 ms 384 KB correct
17 Correct 2 ms 384 KB correct
18 Correct 1 ms 384 KB correct
19 Correct 2 ms 384 KB correct
20 Correct 2 ms 384 KB correct
21 Correct 2 ms 384 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 256 KB correct
26 Correct 2 ms 384 KB correct
27 Correct 2 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 Correct 139 ms 1664 KB correct
35 Correct 136 ms 1536 KB correct
36 Correct 96 ms 1280 KB correct
37 Correct 6 ms 384 KB correct
38 Correct 152 ms 1536 KB correct
39 Correct 74 ms 1656 KB correct
40 Correct 94 ms 1440 KB correct
41 Correct 11 ms 1476 KB correct
42 Correct 10 ms 1536 KB correct
43 Correct 75 ms 1152 KB correct
44 Correct 62 ms 896 KB correct
45 Correct 74 ms 896 KB correct
46 Correct 56 ms 768 KB correct
47 Correct 23 ms 512 KB correct
48 Correct 3 ms 384 KB correct
49 Correct 7 ms 384 KB correct
50 Correct 23 ms 512 KB correct
51 Correct 72 ms 896 KB correct
52 Correct 64 ms 896 KB correct
53 Correct 53 ms 768 KB correct
54 Correct 72 ms 1192 KB correct
55 Correct 71 ms 896 KB correct
56 Correct 72 ms 896 KB correct
57 Correct 77 ms 996 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Incorrect 114 ms 4100 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 0 ms 256 KB correct
4 Correct 1 ms 256 KB correct
5 Correct 0 ms 256 KB correct
6 Correct 1 ms 512 KB correct
7 Correct 0 ms 256 KB correct
8 Correct 1 ms 256 KB correct
9 Correct 1 ms 256 KB correct
10 Correct 0 ms 256 KB correct
11 Correct 1 ms 256 KB correct
12 Correct 1 ms 256 KB correct
13 Correct 1 ms 256 KB correct
14 Correct 2 ms 384 KB correct
15 Correct 1 ms 384 KB correct
16 Correct 1 ms 384 KB correct
17 Correct 2 ms 384 KB correct
18 Correct 1 ms 384 KB correct
19 Correct 2 ms 384 KB correct
20 Correct 2 ms 384 KB correct
21 Correct 2 ms 384 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 256 KB correct
26 Correct 2 ms 384 KB correct
27 Correct 2 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 Correct 139 ms 1664 KB correct
35 Correct 136 ms 1536 KB correct
36 Correct 96 ms 1280 KB correct
37 Correct 6 ms 384 KB correct
38 Correct 152 ms 1536 KB correct
39 Correct 74 ms 1656 KB correct
40 Correct 94 ms 1440 KB correct
41 Correct 11 ms 1476 KB correct
42 Correct 10 ms 1536 KB correct
43 Correct 75 ms 1152 KB correct
44 Correct 62 ms 896 KB correct
45 Correct 74 ms 896 KB correct
46 Correct 56 ms 768 KB correct
47 Correct 23 ms 512 KB correct
48 Correct 3 ms 384 KB correct
49 Correct 7 ms 384 KB correct
50 Correct 23 ms 512 KB correct
51 Correct 72 ms 896 KB correct
52 Correct 64 ms 896 KB correct
53 Correct 53 ms 768 KB correct
54 Correct 72 ms 1192 KB correct
55 Correct 71 ms 896 KB correct
56 Correct 72 ms 896 KB correct
57 Correct 77 ms 996 KB correct
58 Correct 1 ms 256 KB correct
59 Correct 0 ms 256 KB correct
60 Incorrect 114 ms 4100 KB WA in grader: NO
61 Halted 0 ms 0 KB -