#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 5010;
int n, m;
ll len[100010];
bitset < maxn > edge[maxn];
vector < int > adj[100010];
void solve()
{
cin >> n >> m;
/**if (n <= 5000)
{
for (int i = 1; i <= m; i ++)
{
int a, b;
cin >> a >> b;
edge[a][b] = 1;
}
int ans = 0;
for (int i = 1; i <= n; i ++)
{
for (int j = 1; j <= i; j ++)
{
edge[i][j] = 0;
}
for (int j = i + 1; j <= n; j ++)
{
if (edge[i][j] == 1)
{
edge[j] |= edge[i];
}
}
}
for (int i = 1; i <= n; i ++)
{
edge[i][i] = 0;
ans += edge[i].count();
}
cout << ans << endl;
}
else*/
{
for (int i = 1; i <= m; i ++)
{
int a, b;
cin >> a >> b;
adj[a].push_back(b);
}
ll all_edges = m;
for (int i = n; i > 0; i --)
{
ll sum = 0;
///cout << "vertex " << i << endl;
for (int u : adj[i])
{
sum += len[u];
}
///cout << sum << endl;
all_edges += max(0, (int)(adj[i].size()) - 1);
all_edges += max((ll)0, sum - 1);
for (int u : adj[i])
{
//all_edges += (len[u]) * (sum - len[u]);
//sum -= len[u];
len[i] += len[u];
}
len[i] ++;
}
cout << all_edges << endl;
}
}
int main()
{
solve();
return 0;
}
/**
5 3
1 2
1 3
3 4
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
4400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |