結果

問題 No.3512 moesode
コンテスト
ユーザー tau1235
提出日時 2026-04-24 22:06:03
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 791 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,416 ms
コンパイル使用メモリ 343,348 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2026-04-25 04:15:10
合計ジャッジ時間 7,887 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;

int main(){
  using ll=long long;
  ll n,m,k;
  cin>>n>>m>>k;
  vector<pair<int,int>> ab(m);
  vector<bool> out(n);
  vector<int> in(n);
  for (int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    ab[i]={a,b};
    out[a]=true;
    in[b]++;
  }
  int cnt=0,c1=0,c2=0;
  cnt=count(out.begin(),out.end(),true);
  for (int i=0;i<m;i++){
    auto [a,b]=ab[i];
    if (out[a]&&out[b]) c1++;
    else c2++;
  }
  vector<pair<int,int>> vp;
  for (int i=0;i<n;i++){
    if (!out[i]){
      vp.push_back({in[i],i});
    }
  }
  sort(vp.begin(),vp.end());
  ll ans=1e18;
  while (true){
    if (cnt-1>=k) ans=min(ans,cnt*k-c1);
    if (vp.empty()) break;
    auto [c,v]=vp.back();
    vp.pop_back();
    cnt++;
    c1+=c;
  }
  cout<<ans<<endl;
}
0