Submission #35018

#TimeUsernameProblemLanguageResultExecution timeMemory
35018luongduydat스파이 (JOI13_spy)C++14
100 / 100
366 ms247172 KiB
#include <iostream> #include <cmath> #include <cstdio> #include <vector> #include <bitset> using namespace std; template<typename T> inline void read(T &x) { char c; bool neg = false; while (!isdigit(c = getchar()) && c != '-'); x = 0; if (c == '-') { neg = true; c = getchar(); } do { x = x * 10 + c - '0'; } while (isdigit(c = getchar())); if (neg) x = -x; } template<typename T> inline void write(T x) { if (x < 0) { putchar('-'); write(-x);return; } if (x < 10) { putchar(char(x + 48)); } else { write(x/10); putchar(char(48 + x%10)); } } template<typename T> inline void writeln(T x) { write(x); putchar('\n'); } int n,m; vector <int> aj[2005],ai[2005]; bitset<500005> p[2005],q[2005]; void Enter() { read(n);read(m); for (int i=1;i<=n;i++) { int u,v; read(u);read(v); aj[u].push_back(i); ai[v].push_back(i); } } void DFS1(int u) { for (int v:aj[u]) { p[v]|=p[u]; DFS1(v); } } void DFS2(int u) { for (int v:ai[u]) { q[v]|=q[u]; DFS2(v); } } void Solve() { for (int i=0;i<m;i++) { int u,v;read(u);read(v); p[u].set(i); q[v].set(i); } DFS1(aj[0][0]); DFS2(ai[0][0]); for (int i=1;i<=n;i++) { int kq=(p[i]&q[i]).count(); writeln(kq); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); Enter(); Solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...