結果
| 問題 |
No.3103 Butterfly Effect
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-11 23:27:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 858 ms / 5,000 ms |
| コード長 | 1,484 bytes |
| コンパイル時間 | 2,399 ms |
| コンパイル使用メモリ | 207,060 KB |
| 実行使用メモリ | 67,436 KB |
| 最終ジャッジ日時 | 2025-04-11 23:27:40 |
| 合計ジャッジ時間 | 27,865 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 50 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | scanf("%d%d%d", &p, &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
typedef long long ll;
const int N = 2000086, MOD = 998244353, INF = 0x3f3f3f3f;
ll res;
int n, m, cnt, w[N];
int t[N];
bool st[N];
int main() {
cin >> n >> m;
for (int i = 2; i < n + 1; i++) t[i] = INF;
res = 1;
vector<set<pii, greater<pii> > > e(n + 10);
priority_queue<pii, vector<pii>, greater<pii> > q;
for (int i = 1; i < m + 1; i++) {
int p, x, y;
scanf("%d%d%d", &p, &x, &y);
if (p > min(t[x], t[y])) {
if (t[x] > t[y]) swap(x, y);
if (t[x] < p && t[y] > p) {
res += t[y] == INF;
t[y] = p;
q.push({t[y], y});
while (q.size()) {
auto u = q.top().second; q.pop();
while (e[u].size() && e[u].begin()->first > t[u]) {
auto v = *e[u].begin();
e[u].erase(v);
e[v.second].erase({v.first, u});
if (t[v.second] < v.first) continue;
res += t[v.second] == INF;
t[v.second] = v.first;
q.push({v.first, v.second});
}
}
} else e[x].insert({p, y}), e[y].insert({p, x});
} else e[x].insert({p, y}), e[y].insert({p, x});
printf("%lld\n", res);
}
return 0;
}