結果
| 問題 |
No.1244 Black Segment
|
| コンテスト | |
| ユーザー |
auaua
|
| 提出日時 | 2020-10-02 22:58:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,722 bytes |
| コンパイル時間 | 1,766 ms |
| コンパイル使用メモリ | 179,300 KB |
| 実行使用メモリ | 19,888 KB |
| 最終ジャッジ日時 | 2024-07-17 23:02:42 |
| 合計ジャッジ時間 | 8,620 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 RE * 21 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll inf=INF;
const ll MOD=998244353;
const ll mod=MOD;
const int MAX=100010;
vector<ll>dp(MAX);
vector<ll>l(MAX);
vector<ll>r(MAX);
ll n;
vector<vector<pll> >G(100010);
vector<ll> d(100010);
void dijkstra(ll s,vector<vector<pll> >&G,vector<ll> &d){
priority_queue<pll,vector<pll>,greater<pll> >pq;
rep(i,n){
d[i]=inf*inf;
}
d[s]=0;
pq.push(mp(0,s));
while(!pq.empty()){
pll k=pq.top();pq.pop();
ll v=k.second;
if(d[v]<k.first)continue;
for(auto e:G[v]){
if(d[e.first]>d[v]+e.second){
d[e.first]=d[v]+e.second;
pq.push(mp(d[e.first],e.first));
}
}
}
}
signed main(){
ll n_,m,a,b;cin>>n_>>m>>a>>b;
n=n_*2+4;
rep(i,m){
ll l,r;
cin>>l>>r;
if(l<a)G[a].pb(mp(l,0));
G[l].pb(mp(r+1,1));
G[l].pb(mp(n_+2+r,1));
G[r+n_+2].pb(mp(l,1));
G[r+n_+2].pb(mp(l-1+n_+2,1));
}
dijkstra(a,G,d);
ll ans=inf*inf;
REP(i,b+1,n_+2){
ans=min(ans,d[i]);
}
rep(i,n_+2){
//cout<<i<<' '<<d[i]<<endl;
}
if(ans>inf){
cout<<-1<<endl;
}else{
cout<<ans<<endl;
}
}
auaua