結果

問題 No.583 鉄道同好会
ユーザー Gurren47881Gurren47881
提出日時 2017-10-27 23:15:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,541 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 73,644 KB
実行使用メモリ 8,568 KB
最終ジャッジ日時 2023-08-14 04:55:44
合計ジャッジ時間 2,009 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,352 KB
testcase_01 AC 4 ms
6,192 KB
testcase_02 AC 3 ms
6,252 KB
testcase_03 AC 4 ms
6,248 KB
testcase_04 AC 4 ms
6,168 KB
testcase_05 AC 3 ms
6,268 KB
testcase_06 AC 4 ms
6,192 KB
testcase_07 AC 4 ms
6,232 KB
testcase_08 AC 3 ms
6,176 KB
testcase_09 AC 4 ms
6,172 KB
testcase_10 AC 4 ms
6,284 KB
testcase_11 AC 17 ms
6,852 KB
testcase_12 AC 21 ms
7,364 KB
testcase_13 AC 21 ms
7,376 KB
testcase_14 AC 21 ms
7,316 KB
testcase_15 AC 26 ms
7,364 KB
testcase_16 AC 46 ms
8,064 KB
testcase_17 AC 54 ms
8,568 KB
testcase_18 AC 53 ms
8,344 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:69:11: 警告: ‘first’ may be used uninitialized [-Wmaybe-uninitialized]
   69 |   dijkstra(first);
      |   ~~~~~~~~^~~~~~~
main.cpp:50:7: 備考: ‘first’ はここで定義されています
   50 |   int first;
      |       ^~~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
typedef long long ll;

#define MV 100000
#define INF 1e9

struct edge{int to,cost; };
vector <edge> G[MV];
bool used[MV];
int d[MV+1];

int V,E;

void dijkstra(int first){
  fill(d,d+MV,INF);
  fill(used,used+MV,false);
  d[first] = 0;

  for(int i = 0;i < V;i++){
    int now = MV;

    for(int j = 0;j < V;j++){
      if(used[j] == false && d[now] > d[j]){
	now = j;
      }
    }
    // cout << now << endl; デバッグ用、条件1が正しく動作しているかを確かめられる
    used[now] = true;
    for(int j = 0;j < G[now].size();j++){
      edge e = G[now][j];
      d[e.to] = min(d[e.to] , d[now]+e.cost);
    }
    /*for(int j = 0;j < V;j++)
      cout << d[j] << "   ";
      cout << endl; 
デバッグ用で、各点の更新後の最短経路が見れる
*/
    
  }
}


int main(){
  d[MV] = INF+10;
  int first;
  
  cin >> V >> E;
  int a[V] = {0};
  for(int i = 0;i < E;i++){
    int f,t;
    edge e;
    cin >> f >> e.to;
    a[f]++;
    a[e.to]++;
    first = f;
    e.cost = 1;
    G[f].push_back(e);
    t = e.to;
    e.to = f;
      G[t].push_back(e);
  }

  
  dijkstra(first);
  int r = 0,sum = 0,ki = 0;
  REP(i,V){
    if(d[i] == INF)
      r++;
    if(a[i] == 0)
      sum++;
    if(a[i]%2 == 1)
      ki++;
  }
  if(r == sum){
    if(ki <= 2)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  
}
0