Submission #761379

# Submission time Handle Problem Language Result Execution time Memory
761379 2023-06-19T14:52:37 Z minhcool Toy Train (IOI17_train) C++17
100 / 100
395 ms 15564 KB
//#define local
#ifndef local
#include "train.h"
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;

const int oo = 1e18 + 7, mod = 1e9 + 7;

int n, a[N];

mt19937 rng(1);

int rnd(int l, int r){
	int temp = rng() % (r - l + 1);
	return abs(temp) + l;
}

vector<int> Adj[N], Adj2[N];

bool out[N];

int deg[N], deg2[N];

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> U, vector<int> V){
	n = a.size();
	for(int i = 0; i < U.size(); i++){
		Adj[V[i]].pb(U[i]);
		Adj2[U[i]].pb(V[i]);
		//Adj[U[i]].pb(V[i]);
	}
	for(int i = 0; i < n; i++) deg2[i] = Adj2[i].size();
	while(1){
		vector<bool> vis(n + 1);
		for(int i = 0; i < n; i++){
			if(out[i]) continue;
			vis[i] = r[i];
			deg[i] = 0;
		}
		queue<int> q;
		for(int i = 0; i < n; i++){
			if(out[i]) continue;
			if(r[i]) q.push(i);
		}
		while(!q.empty()){
			int u = q.front();
		//	cout << u << "\n";
			vis[u] = 1;
			q.pop();
			for(auto v : Adj[u]){
				if(vis[v]) continue;
				if(out[v]) continue;
				deg[v]++;
				if(a[v] == 1 && deg[v] == 1){
					q.push(v);
					vis[v] = 1;
				}
				if(a[v] == 0 && deg[v] == deg2[v]){
					q.push(v);
					vis[v] = 1;
				}		
			}
			//vis[u] = 1;
			//for(auto v : Adj[u]){
			//	if(vis[v] || out[v]) continue;
			//	q.push(v);
			//}
		}
		while(!q.empty()) q.pop();
		//cout << "\n";
		for(int i = 0; i < n; i++){
			if(!out[i] && !vis[i]){
		//		if(i == 3015) cout << "????\n";
				q.push(i);
				vis[i] = 1;
			//	cout << "OK " << i << "\n";
			}
			else vis[i] = 0;
			deg[i] = 0;
		}
		while(!q.empty()){
			int u = q.front();
			q.pop();
			//cout << "OK " << u << "\n";
			vis[u] = 1;
			//if(u == 3015) cout << u << "\n";
			for(auto v : Adj[u]){
				if(vis[v]) continue;
				if(out[v]) continue;
				deg[v]++;
			//	if(v == 853) cout << u << " " <<  a[v] << " " << deg[v] << " " << deg2[v] << " "<< vis[v] << "\n";
				if(a[v] == 0 && deg[v] == 1){
			//		if(v == 3015) cout << "???\n";
					q.push(v);
					vis[v] = 1;
				}
				if(a[v] == 1 && deg[v] == deg2[v]){
			//		if(v == 3015) cout << "???\n";
					q.push(v);
					vis[v] = 1;
				}
			}	
		}
		//exit(0);
		int cnt = 0;
		for(int i = 0; i < n; i++){
			if(out[i] || !vis[i]) continue;
		//	cout << i << "\n";
			out[i] = 1;
			for(auto it : Adj[i]) deg2[it]--;
			cnt++;
		}
	//	cout << out[853] << "\n";
		if(!cnt) break;
	}	
	vector<int> ans;
	for(int i = 0; i < n; i++) ans.pb(!out[i]);
	return ans;
}

//#define local
#ifdef local
void process(){
	int n, m;
	cin >> n >> m;
	vector<int> v1, v2;
	v1.resize(n), v2.resize(n);
	vector<int> v3, v4;
	for(int i = 0; i < n; i++) cin >> v1[i];
	for(int i = 0; i < n; i++) cin >> v2[i];
	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		v3.pb(x), v4.pb(y);
	}
	vector<int> v = who_wins(v1, v2, v3, v4);
	for(int i = 0; i < n; i++) cout << v[i] << " ";
	cout << "\n";
	//for(int i = 0; i < n; i++) if(v[i]) cout << i << "\n";
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//	freopen("train.inp", "r", stdin);
	process();
}
#endif

Compilation message

train.cpp:22:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   22 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for(int i = 0; i < U.size(); i++){
      |                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14932 KB Output is correct
2 Correct 11 ms 14932 KB Output is correct
3 Correct 11 ms 14996 KB Output is correct
4 Correct 12 ms 14936 KB Output is correct
5 Correct 10 ms 14908 KB Output is correct
6 Correct 10 ms 14932 KB Output is correct
7 Correct 10 ms 14932 KB Output is correct
8 Correct 11 ms 14932 KB Output is correct
9 Correct 10 ms 14992 KB Output is correct
10 Correct 10 ms 14932 KB Output is correct
11 Correct 10 ms 14988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14548 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14292 KB Output is correct
10 Correct 7 ms 14376 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14344 KB Output is correct
16 Correct 7 ms 14356 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 7 ms 14420 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 15320 KB Output is correct
2 Correct 137 ms 15316 KB Output is correct
3 Correct 184 ms 15304 KB Output is correct
4 Correct 13 ms 15284 KB Output is correct
5 Correct 14 ms 15316 KB Output is correct
6 Correct 14 ms 15448 KB Output is correct
7 Correct 14 ms 15496 KB Output is correct
8 Correct 13 ms 15444 KB Output is correct
9 Correct 12 ms 15488 KB Output is correct
10 Correct 13 ms 15468 KB Output is correct
11 Correct 14 ms 15464 KB Output is correct
12 Correct 12 ms 15444 KB Output is correct
13 Correct 14 ms 15444 KB Output is correct
14 Correct 13 ms 15444 KB Output is correct
15 Correct 17 ms 15552 KB Output is correct
16 Correct 13 ms 15528 KB Output is correct
17 Correct 13 ms 15444 KB Output is correct
18 Correct 266 ms 15116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15060 KB Output is correct
2 Correct 12 ms 15240 KB Output is correct
3 Correct 13 ms 15316 KB Output is correct
4 Correct 13 ms 15316 KB Output is correct
5 Correct 13 ms 15248 KB Output is correct
6 Correct 12 ms 15316 KB Output is correct
7 Correct 13 ms 15236 KB Output is correct
8 Correct 12 ms 15208 KB Output is correct
9 Correct 12 ms 15188 KB Output is correct
10 Correct 12 ms 15256 KB Output is correct
11 Correct 14 ms 15244 KB Output is correct
12 Correct 12 ms 15312 KB Output is correct
13 Correct 13 ms 15316 KB Output is correct
14 Correct 12 ms 15268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 15332 KB Output is correct
2 Correct 13 ms 15440 KB Output is correct
3 Correct 13 ms 15556 KB Output is correct
4 Correct 12 ms 15392 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 10 ms 15020 KB Output is correct
7 Correct 11 ms 15092 KB Output is correct
8 Correct 11 ms 15060 KB Output is correct
9 Correct 11 ms 15060 KB Output is correct
10 Correct 8 ms 14636 KB Output is correct
11 Correct 10 ms 15060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14932 KB Output is correct
2 Correct 11 ms 14932 KB Output is correct
3 Correct 11 ms 14996 KB Output is correct
4 Correct 12 ms 14936 KB Output is correct
5 Correct 10 ms 14908 KB Output is correct
6 Correct 10 ms 14932 KB Output is correct
7 Correct 10 ms 14932 KB Output is correct
8 Correct 11 ms 14932 KB Output is correct
9 Correct 10 ms 14992 KB Output is correct
10 Correct 10 ms 14932 KB Output is correct
11 Correct 10 ms 14988 KB Output is correct
12 Correct 9 ms 14548 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 7 ms 14420 KB Output is correct
17 Correct 7 ms 14292 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 7 ms 14420 KB Output is correct
20 Correct 7 ms 14292 KB Output is correct
21 Correct 7 ms 14376 KB Output is correct
22 Correct 7 ms 14420 KB Output is correct
23 Correct 7 ms 14420 KB Output is correct
24 Correct 7 ms 14420 KB Output is correct
25 Correct 7 ms 14420 KB Output is correct
26 Correct 7 ms 14344 KB Output is correct
27 Correct 7 ms 14356 KB Output is correct
28 Correct 7 ms 14420 KB Output is correct
29 Correct 7 ms 14420 KB Output is correct
30 Correct 7 ms 14420 KB Output is correct
31 Correct 7 ms 14420 KB Output is correct
32 Correct 71 ms 15320 KB Output is correct
33 Correct 137 ms 15316 KB Output is correct
34 Correct 184 ms 15304 KB Output is correct
35 Correct 13 ms 15284 KB Output is correct
36 Correct 14 ms 15316 KB Output is correct
37 Correct 14 ms 15448 KB Output is correct
38 Correct 14 ms 15496 KB Output is correct
39 Correct 13 ms 15444 KB Output is correct
40 Correct 12 ms 15488 KB Output is correct
41 Correct 13 ms 15468 KB Output is correct
42 Correct 14 ms 15464 KB Output is correct
43 Correct 12 ms 15444 KB Output is correct
44 Correct 14 ms 15444 KB Output is correct
45 Correct 13 ms 15444 KB Output is correct
46 Correct 17 ms 15552 KB Output is correct
47 Correct 13 ms 15528 KB Output is correct
48 Correct 13 ms 15444 KB Output is correct
49 Correct 266 ms 15116 KB Output is correct
50 Correct 11 ms 15060 KB Output is correct
51 Correct 12 ms 15240 KB Output is correct
52 Correct 13 ms 15316 KB Output is correct
53 Correct 13 ms 15316 KB Output is correct
54 Correct 13 ms 15248 KB Output is correct
55 Correct 12 ms 15316 KB Output is correct
56 Correct 13 ms 15236 KB Output is correct
57 Correct 12 ms 15208 KB Output is correct
58 Correct 12 ms 15188 KB Output is correct
59 Correct 12 ms 15256 KB Output is correct
60 Correct 14 ms 15244 KB Output is correct
61 Correct 12 ms 15312 KB Output is correct
62 Correct 13 ms 15316 KB Output is correct
63 Correct 12 ms 15268 KB Output is correct
64 Correct 13 ms 15332 KB Output is correct
65 Correct 13 ms 15440 KB Output is correct
66 Correct 13 ms 15556 KB Output is correct
67 Correct 12 ms 15392 KB Output is correct
68 Correct 8 ms 14420 KB Output is correct
69 Correct 10 ms 15020 KB Output is correct
70 Correct 11 ms 15092 KB Output is correct
71 Correct 11 ms 15060 KB Output is correct
72 Correct 11 ms 15060 KB Output is correct
73 Correct 8 ms 14636 KB Output is correct
74 Correct 10 ms 15060 KB Output is correct
75 Correct 108 ms 15476 KB Output is correct
76 Correct 150 ms 15508 KB Output is correct
77 Correct 199 ms 15564 KB Output is correct
78 Correct 199 ms 15508 KB Output is correct
79 Correct 199 ms 15520 KB Output is correct
80 Correct 13 ms 15444 KB Output is correct
81 Correct 14 ms 15448 KB Output is correct
82 Correct 13 ms 15444 KB Output is correct
83 Correct 14 ms 15444 KB Output is correct
84 Correct 14 ms 15440 KB Output is correct
85 Correct 13 ms 15484 KB Output is correct
86 Correct 15 ms 15452 KB Output is correct
87 Correct 13 ms 15448 KB Output is correct
88 Correct 16 ms 15444 KB Output is correct
89 Correct 14 ms 15452 KB Output is correct
90 Correct 18 ms 15448 KB Output is correct
91 Correct 17 ms 15444 KB Output is correct
92 Correct 24 ms 15488 KB Output is correct
93 Correct 26 ms 15448 KB Output is correct
94 Correct 25 ms 15444 KB Output is correct
95 Correct 26 ms 15440 KB Output is correct
96 Correct 68 ms 15372 KB Output is correct
97 Correct 240 ms 15480 KB Output is correct
98 Correct 388 ms 15444 KB Output is correct
99 Correct 395 ms 15424 KB Output is correct
100 Correct 262 ms 15116 KB Output is correct