This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
vector<int> G[N], H[N];
int n, m;
void Add(int u, int v){
G[u].pb(v);
H[v].pb(u);
}
int ps[N];
int Solve(int l, int r){
memset(ps, 0, sizeof ps);
multiset<int> ms;
int res = 0;
for(int i = l; i < r - 1; i++){
for(auto x : G[i]){
if(x >= r) continue;
ps[i] ++;
ps[x] --;
ms.insert(x);
// debug(x);
}
ps[i] += ps[i - 1];
while(ps[i] > 0){
int fr = *ms.rbegin();
// debug(fr);
ms.erase(ms.find(fr));
ps[i] -= 2;
ps[fr] += 2;
res ++;
// cerr << i << " : " << fr << '\n';
}
}
// cerr << l << " , " << r << " : " << res << '\n';
// exit(0);
return res;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
int a, b, c;
for(int i = 0; i < m; i++){
cin >> a >> b >> c;
assert(c == 1);
if(a > b) swap(a, b);
Add(a, b);
Add(b, n + a);
Add(n + a, n + b);
}
int ans = m;
for(int i = 1; i <= n; i++){
ans = min(ans, Solve(i, n + i));
// break;
}
cout << ans << '\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |