結果
| 問題 |
No.3103 Butterfly Effect
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-11 23:13:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,263 bytes |
| コンパイル時間 | 2,596 ms |
| コンパイル使用メモリ | 210,020 KB |
| 実行使用メモリ | 66,632 KB |
| 最終ジャッジ日時 | 2025-04-11 23:14:17 |
| 合計ジャッジ時間 | 30,927 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 46 TLE * 1 -- * 3 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N,Q; cin >> N >> Q;
vector<map<int,int,greater<>>> Hold(N);
int answer = 1;
vector<int> T(N,Q+1); T.at(0) = 0;
for(int t=0; t<Q; t++){
int p,x,y; cin >> p >> x >> y; p--; x--; y--;
int xt = T.at(x),yt = T.at(y);
if(xt < p && yt < p){}
else if(xt > p && yt > p) Hold.at(x)[p] = y,Hold.at(y)[p] = x;
else{
if(xt > p) swap(x,y),swap(xt,yt);
if(T.at(y) == Q+1) answer++;
T.at(y) = p;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<>> PQ;
PQ.push({p,y});
while(PQ.size()){
auto [ti,pos] = PQ.top(); PQ.pop();
if(T.at(pos) != ti) continue;
vector<int> era;
for(auto [k,to] : Hold.at(pos)){
if(k < ti) break;
if(T.at(to) > k){
if(T.at(to) == Q+1) answer++;
T.at(to) = k; PQ.push({k,to});
}
}
for(auto e : era) Hold.at(pos).erase(e);
}
}
cout << answer << "\n";
}
}