結果
| 問題 | No.3751 Nonopoly |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-02 21:48:00 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 49 ms / 2,000 ms |
| + 756µs | |
| コード長 | 898 bytes |
| 記録 | |
| コンパイル時間 | 1,332 ms |
| コンパイル使用メモリ | 223,552 KB |
| 実行使用メモリ | 9,872 KB |
| 最終ジャッジ日時 | 2026-10-02 21:48:09 |
| 合計ジャッジ時間 | 7,203 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1; //cin >> T;
while(T--){
int N,M; cin >> N >> M;
vector<pair<long long,int>> V(N);
vector<tuple<int,int,int>> edge(M);
for(auto &[a,b,c] : edge){
cin >> a >> b >> c,a--,b--;
V.at(a).first += c;
V.at(b).first += c;
}
for(int i=0; i<N; i++) V.at(i).second = i;
sort(V.rbegin(),V.rend());
vector<int> C(N);
for(int i=0; i<N; i++){
auto [ign,pos] = V.at(i);
C.at(pos) = i%2;
}
long long answer = 0;
for(auto [a,b,c] : edge){
if(C.at(a) == C.at(b)){
if(C.at(a) == 0) answer += c;
else answer -= c;
}
}
cout << answer << "\n";
}
}