이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const int maxn = 1e6 + 5;
int n,q;
set<int> g[maxn];
void add_edge(int u, int v) {
g[u].insert(v);
}
void relax() {
while (true) {
bool ok = false;
for (int x=0; x<n && !ok; x++) {
for (int y: g[x]) {
if (ok) break;
for (int z: g[y]) {
if (g[z].count(y) && !g[x].count(z) && x!=z) {
g[x].insert(z);
ok = true;
break;
}
}
}
}
if (!ok) break;
}
}
ll count() {
ll res = 0;
for (int i=0; i<n; i++) {
res += g[i].size();
}
// for (int i=0; i<n; i++) {
// for (int j: g[i]) {
// cout<<i+1<<"->"<<j+1<<endl;
// }
// }
return res;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>q;
while (q--) {
int u,v;
cin>>u>>v;
--u; --v;
add_edge(u,v);
relax();
cout<<count()<<"\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |