#include <bits/stdc++.h>
using namespace std;
const int Nmax = 2e5 + 5;
priority_queue<int> heap;
int start[Nmax], finish[Nmax], add[Nmax], dp[Nmax];
vector<int> v[Nmax];
int n, m, i;
bool check(int L)
{
int i, need = 0, nr;
for(i=1; i<=n; ++i)
{
start[i] = v[i].size(); add[i] = 0;
for(auto it : v[i]) finish[it] ++;
}
dp[0] = L;
for(i=1; i<n; ++i)
{
for(auto it : v[i]) heap.push(it);
dp[i] = dp[i-1] + start[i] - finish[i] + add[i];
while(dp[i] > L && need <= L)
{
assert(heap.size());
dp[i] -= 2;
nr = heap.top();
heap.pop();
add[nr] += 2;
++need;
}
if(need > L) return 0;
}
return (need <= L);
}
int main()
{
/// freopen("input", "r", stdin);
cin >> n >> m;
int i, x, y, C;
for(i=1; i<=m; ++i)
{
cin >> x >> y >> C;
if(x > y) swap(x, y);
v[x].push_back(y);
}
for(i=1; i<=n; ++i) sort(v[i].begin(), v[i].end());
int st = 0, dr = m, mid;
while(st <= dr)
{
mid = (st+dr) / 2;
if(check(mid)) dr = mid-1;
else st = mid+1;
}
cout << st << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
5112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |