Submission #789571

# Submission time Handle Problem Language Result Execution time Memory
789571 2023-07-21T14:01:22 Z esomer Toy Train (IOI17_train) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "train.h"

using namespace std;

typedef long long ll;

int DFS(int x, vector<vector<int>>& adj, vector<bool>& vis, vector<bool>& forced){
	if(forced[x] == 1) return 1;
	else if(vis[x] == 1) return 0;
	vis[x] = 1;
	int mn = 1;
	for(int node : adj[x]){
		mn = min(mn, DFS(node, adj, vis, forced));
	}
	if(mn == 1) forced[x] = 1;
	else forced[x] = 0;
	return mn;
}

vector<int> who_wins(vector<int> A, vector<int> R, vector<int> U, vector<int> V){
	int n = (int)A.size();
	int m = (int)U.size();
	vector<vector<int>> adj(n);
	vector<vector<int>> radj(n);
	vector<int> out(n, 0);
	for(int i = 0; i < m; i++){
		adj[U[i]].push_back(V[i]);
		if(R[U[i]] == 1 || R[V[i]] == 1) continue;
		out[U[i]]++;
		radj[V[i]].push_back(U[i]);
	}
	vector<bool> forced(n, 1); //If 1, then it can be forced by B into a cycle with no R's.
	queue<int> q;
	for(int i = 0; i < n; i++){
		if(out[i] == 0 && R[i] == 0){
			forced[i] = 0;
			q.push(i);
		}
	}
	while(!q.empty()){
		int x = q.front(); q.pop();
		for(int node : radj[x]){
			out[node]--;
			if(out[node] == 0 && forced[node] == 1) {q.push(node); forced[node] = 0;}
			if(A[node] == 1 && forced[node] == 1){
				forced[node] = 0;
				q.push(node);
			}
		}
	}
	for(int i = 0; i < n; i++){
		bool has = 0;
		for(int node : adj[i]){
			if(R[node] == 1) has = 1;
		}
		if(R[i] == 1 || (has == 1 && A[i] == 1)) forced[i] = 0;
	}
	vector<bool> vis(n, 0);
	for(int i = 0; i < n; i++){
		if(!vis[i]){
			DFS(i, adj, vis, forced);
		}
	}
	vector<int> ans(n);
	for(int i = 0; i < n; i++){
		if(forced[i] == 1) ans[i] = 0;
		else ans[i] = 1;
	}
	return ans;
}

int main() {
	
	freopen("in.txt", "r", stdin);
	
	int n, m;
	assert(2 == scanf("%d %d", &n, &m));

	vector<int> a(n), r(n), u(m), v(m);

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &a[i]));

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &r[i]));

	for(int i = 0; i < m; i++)
		assert(2 == scanf("%d %d", &u[i], &v[i]));

	vector<int> res = who_wins(a, r, u, v);

	for(int i = 0; i < (int)res.size(); i++)
		printf(i ? " %d" : "%d", res[i]);
	printf("\n");

	return 0;
}

Compilation message

train.cpp: In function 'int main()':
train.cpp:75:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |  freopen("in.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccmDR8i3.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc9SE131.o:train.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status