Submission #3048911


Source Code Expand

#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 200000, MAX_M = 200000;
int N, M;
int a[MAX_M], b[MAX_N];
                            
struct edge { 
  edge(int t, int c) {
    to = t; cost = c;
  }
  int to, cost; 
};
const int MAX_V = MAX_N, INF = 10000000;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
  fill(d, d+V, INF);
  priority_queue<pii, vector<pii>, greater<pii> > pque;
  d[s] = 0;
  pque.push(pii(0, s));


  while (!pque.empty()) {
    pii p = pque.top(); pque.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < (int)G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost; 
        pque.push(pii(d[v]+ e.cost, e.to));
      }
    }
  }
}

int main() {
  cin >> N >> M;
  rep(i,M) cin >> a[i] >> b[i];
  V = N;

  for (int i = 0; i < M; ++i) {
    G[a[i]-1].push_back(edge(b[i]-1, 1));
    G[b[i]-1].push_back(edge(a[i]-1, 1));
  }

  dijkstra(0);

  if (d[N-1] == 2) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

  return 0;
}

Submission Info

Submission Time
Task C - Cat Snuke and a Voyage
User Bobyama
Language C++14 (Clang 3.8.0)
Score 300
Code Size 1620 Byte
Status AC
Exec Time 390 ms
Memory 16616 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 11
Set Name Test Cases
Sample example0, example1, example2, example3
All example0, example1, example2, example3, last0, last1, many0, many1, rand0, rand1, rand2
Case Name Status Exec Time Memory
example0 AC 3 ms 4992 KB
example1 AC 2 ms 4992 KB
example2 AC 3 ms 5376 KB
example3 AC 3 ms 4992 KB
last0 AC 390 ms 14720 KB
last1 AC 388 ms 14720 KB
many0 AC 336 ms 16616 KB
many1 AC 352 ms 16616 KB
rand0 AC 250 ms 11776 KB
rand1 AC 381 ms 16508 KB
rand2 AC 206 ms 11008 KB