Submission #797531

# Submission time Handle Problem Language Result Execution time Memory
797531 2023-07-29T14:56:33 Z alvingogo Simurgh (IOI17_simurgh) C++14
51 / 100
78 ms 5300 KB
#include "simurgh.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;

struct DSU{
	vector<int> bo;
	void init(int x){
		bo.resize(x);
		iota(bo.begin(),bo.end(),0);
	}
	int find(int x){
		return bo[x]==x?x:bo[x]=find(bo[x]);
	}
	int merge(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y){
			return 0;
		}
		bo[x]=y;
		return 1;
	}
}dsu;

int query(const vector<int>& r){
	return count_common_roads(r);
}
vector<int> ans,vis;
vector<vector<pair<int,int> > > e;
struct TR{
	struct no{
		vector<pair<int,int> > ch;
		vector<int> sub;
	};
	vector<int> s;
	int pas;
	vector<no> v;
	int n;
	void init(int x){
		n=x;
		v.resize(n);
		for(int i=0;i<n;i++){
			v[i].sub.resize(n);
		}
	}
	void add(int x,int y,int t){
		v[x].ch.push_back({y,t});
		v[y].ch.push_back({x,t});
		s.push_back(t);
		vis[t]=1;
	}
	void dfs(int r,int f,int k){
		v[r].sub[r]=1;
		for(auto h:v[r].ch){
			if(h.fs!=f){
				dfs(h.fs,r,h.sc);
				for(int i=0;i<n;i++){
					v[r].sub[i]|=v[h.fs].sub[i];
				}
			}
		}
		if(r==f){
			return;
		}
		int val=-1;
		vector<int> ud;
		vector<int> l;
		for(int i=0;i<n;i++){
			if(v[r].sub[i]){
				for(auto h:e[i]){
					if(v[r].sub[h.fs]){
						continue;
					}
					if(vis[h.sc]){
						l.push_back(h.sc);
					}
					else{
						vis[h.sc]=1;
						auto z=s;
						for(auto &e:z){
							if(e==k){
								e=h.sc;
							}
						}
						int u=query(z)-pas;
						if(u==1){
							if(val==-1){
								val=0;
								for(auto e:ud){
									ans[e]=0;
								}
							}
							ans[h.sc]=1;
						}
						else if(u==-1){
							if(val==-1){
								val=1;
								for(auto e:ud){
									ans[e]=1;
								}
							}
							ans[h.sc]=0;
						}
						else{
							ud.push_back(h.sc);
						}
					}
				}
			}
		}
		if(val==-1){
			if(l.size()){
				auto h=l[0];
				auto z=s;
				for(auto &e:z){
					if(e==k){
						e=h;
					}
				}
				int u=query(z)-pas;
				if(u==0){
					val=ans[h];
				}
				else{
					val=1-ans[h];
				}
			}
			else{
				val=1;
			}
		}
		for(auto h:ud){
			ans[h]=val;
		}
		ans[k]=val;
	}
}tr;
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	int m=u.size();
	ans.resize(m);
	vis.resize(m);
	dsu.init(n);
	tr.init(n);
	e.resize(n);
	for(int i=0;i<m;i++){
		if(dsu.merge(u[i],v[i])){
			tr.add(u[i],v[i],i);
		}
		else{
			e[u[i]].push_back({v[i],i});
			e[v[i]].push_back({u[i],i});
		}
	}
	tr.pas=query(tr.s);
	tr.dfs(0,0,-1);
	vector<int> ret;
	for(int i=0;i<m;i++){
		if(ans[i]){
			ret.push_back(i);
		}
	}
	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 0 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 296 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 0 ms 296 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 0 ms 212 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 0 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 296 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 0 ms 296 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 2 ms 340 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 340 KB correct
17 Correct 1 ms 300 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 1 ms 340 KB correct
20 Correct 1 ms 340 KB correct
21 Correct 1 ms 308 KB correct
22 Correct 1 ms 300 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 0 ms 212 KB correct
26 Correct 1 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 212 KB correct
29 Correct 1 ms 300 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 0 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 296 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 0 ms 296 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 2 ms 340 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 340 KB correct
17 Correct 1 ms 300 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 1 ms 340 KB correct
20 Correct 1 ms 340 KB correct
21 Correct 1 ms 308 KB correct
22 Correct 1 ms 300 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 0 ms 212 KB correct
26 Correct 1 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 212 KB correct
29 Correct 1 ms 300 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
34 Correct 76 ms 2044 KB correct
35 Correct 76 ms 2072 KB correct
36 Correct 52 ms 1740 KB correct
37 Correct 4 ms 596 KB correct
38 Correct 78 ms 2040 KB correct
39 Correct 69 ms 1916 KB correct
40 Correct 52 ms 1744 KB correct
41 Correct 78 ms 2028 KB correct
42 Correct 75 ms 2076 KB correct
43 Correct 39 ms 1540 KB correct
44 Correct 31 ms 1236 KB correct
45 Correct 37 ms 1308 KB correct
46 Correct 28 ms 1108 KB correct
47 Correct 12 ms 856 KB correct
48 Correct 2 ms 468 KB correct
49 Correct 4 ms 596 KB correct
50 Correct 11 ms 856 KB correct
51 Correct 36 ms 1308 KB correct
52 Correct 33 ms 1220 KB correct
53 Correct 29 ms 1152 KB correct
54 Correct 38 ms 1524 KB correct
55 Correct 34 ms 1236 KB correct
56 Correct 34 ms 1328 KB correct
57 Correct 33 ms 1236 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Incorrect 66 ms 5300 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB correct
2 Correct 0 ms 212 KB correct
3 Correct 1 ms 212 KB correct
4 Correct 0 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 296 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 212 KB correct
9 Correct 0 ms 296 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 1 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 2 ms 340 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 340 KB correct
17 Correct 1 ms 300 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 1 ms 340 KB correct
20 Correct 1 ms 340 KB correct
21 Correct 1 ms 308 KB correct
22 Correct 1 ms 300 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 0 ms 212 KB correct
26 Correct 1 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 212 KB correct
29 Correct 1 ms 300 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
34 Correct 76 ms 2044 KB correct
35 Correct 76 ms 2072 KB correct
36 Correct 52 ms 1740 KB correct
37 Correct 4 ms 596 KB correct
38 Correct 78 ms 2040 KB correct
39 Correct 69 ms 1916 KB correct
40 Correct 52 ms 1744 KB correct
41 Correct 78 ms 2028 KB correct
42 Correct 75 ms 2076 KB correct
43 Correct 39 ms 1540 KB correct
44 Correct 31 ms 1236 KB correct
45 Correct 37 ms 1308 KB correct
46 Correct 28 ms 1108 KB correct
47 Correct 12 ms 856 KB correct
48 Correct 2 ms 468 KB correct
49 Correct 4 ms 596 KB correct
50 Correct 11 ms 856 KB correct
51 Correct 36 ms 1308 KB correct
52 Correct 33 ms 1220 KB correct
53 Correct 29 ms 1152 KB correct
54 Correct 38 ms 1524 KB correct
55 Correct 34 ms 1236 KB correct
56 Correct 34 ms 1328 KB correct
57 Correct 33 ms 1236 KB correct
58 Correct 0 ms 212 KB correct
59 Correct 0 ms 212 KB correct
60 Incorrect 66 ms 5300 KB WA in grader: NO
61 Halted 0 ms 0 KB -