Submission #652201

# Submission time Handle Problem Language Result Execution time Memory
652201 2022-10-21T16:52:39 Z DP_196 스파이 (JOI13_spy) C++14
0 / 100
3 ms 468 KB
#include<bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define MASK(i) (1ll << (i))
#define BIT(x, i) (((x) >> (i)) & 1ll)
#define builtin_popcount __builtin_popcountll

#define dbg(...) cerr << "#" << __LINE__ << ":[" << #__VA_ARGS__ \
<< "] = [" ,DBG(__VA_ARGS__)

string to_string(const string& s) { return '"' + s + '"'; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
        cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...);
}

const int N = (int)1e5 + 5;
const int Sz = (int)5e5 + 2;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
/***------------------------- END ---------------------------***/
int n, m, r1, r2, res[2005];
vector<int> adj[2005], g[2005];
bitset<Sz> bit1[2005], bit2[2005];

void dfs1(int u) {
	for (auto v : adj[u]) {
		bit1[v] |= bit1[u];
		dfs1(v);
	}
}

void dfs2(int u) {
	res[u] = (bit1[u] & bit2[u]).count();
	for (auto v : g[u]) {
		bit2[v] |= bit2[u];
		dfs2(v);
	}
}

#define TASK ""
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	#ifndef ONLINE_JUDGE
 		freopen(TASK".inp", "r", stdin);
	//	freopen(TASK".out", "w", stdout);
	#endif
	
	cin >> n >> m;
	
	for (int i = 1; i <= n; i++) {
		int u, v;
		cin >> u >> v;
		
		if (!u) r1 = i; else adj[u].push_back(i);
		if (!v) r2 = i; else g[v].push_back(i);
	}
	
	for (int i = 1; i <= m; i++) {
		int x, y;
		cin >> x >> y;
		bit1[x][i] = bit2[y][i] = 1;
	}
	
	dfs1(r1);
	dfs2(r2);
	
	for (int i = 1; i <= n; i++) cout << res[i] << '\n';
	
	return 0;
}

Compilation message

spy.cpp: In function 'int main()':
spy.cpp:47:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |    freopen(TASK".inp", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -