提出 #38389924


ソースコード 拡げる

#include <bits/stdc++.h>
#define st first
#define nd second
#define db double
#define re register
#define pb push_back
#define mk make_pair
#define int long long
#define ldb long double
#define pii pair<int, int>
#define ull unsigned long long
#define mst(a, b) memset(a, b, sizeof(a))
using namespace std;
const int N = 2e5 + 10;
inline int read()
{
  int s = 0, w = 1;
  char ch = getchar();
  while(ch < '0' || ch > '9') { if(ch == '-') w *= -1; ch = getchar(); }
  while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
int n, m;
bool vis[N];
vector<int> G[N];
inline void DFS(int u)
{
  vis[u] = true;
  for(re int to : G[u]) if(!vis[to]) DFS(to);
}
signed main()
{
  n = read(), m = read();
  if(m != n - 1) puts("No"), exit(0);
  for(re int i = 1, x, y; i <= m; i++)
    x = read(), y = read(), G[x].pb(y), G[y].pb(x);
  DFS(1);
  for(re int i = 1; i <= n; i++)
    if(!vis[i]) puts("No"), exit(0); //不连通
  for(re int i = 1; i <= n; i++)
    if(G[i].size() > 2) puts("No"), exit(0);
  int cnt = 0;
  for(re int i = 1; i <= n; i++)
    if(G[i].size() == 1) cnt += 1;
  if(cnt != 2) puts("No"), exit(0);
  puts("Yes");
  return 0;
}

提出情報

提出日時
問題 C - Path Graph?
ユーザ Booksnow
言語 C++ (GCC 9.2.1)
得点 300
コード長 1222 Byte
結果 AC
実行時間 66 ms
メモリ 20536 KiB

コンパイルエラー

./Main.cpp: In function ‘void DFS(long long int)’:
./Main.cpp:29:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   29 |   for(re int to : G[u]) if(!vis[to]) DFS(to);
      |              ^~
./Main.cpp: In function ‘int main()’:
./Main.cpp:35:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   35 |   for(re int i = 1, x, y; i <= m; i++)
      |              ^
./Main.cpp:35:21: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   35 |   for(re int i = 1, x, y; i <= m; i++)
      |                     ^
./Main.cpp:35:24: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   35 |   for(re int i = 1, x, y; i <= m; i++)
      |                        ^
./Main.cpp:36:38: warning: address requested for ‘y’, which is declared ‘register’ [-Wextra]
   36 |     x = read(), y = read(), G[x].pb(y), G[y].pb(x);
      |                                      ^
./Main.cpp:36:50: warning: address requested for ‘x’, which is declared ‘register’ [-Wextra]
   36 |     x = read(), y = read(), G[x].pb(y), G[y].pb(x);
      |                                                  ^
./Main.cpp:38:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   38 |   for(re int i = 1; i <= n; i++)
      |              ^
./Main.cpp:40:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   40 |   for(re int i = 1; i <= n; i++)
      |              ^
./Main.cpp:43:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
   43 |   for(re int i = 1; i <= n; i++)
      |              ^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 36
セット名 テストケース
Sample 00_example_00.txt, 00_example_01.txt, 00_example_02.txt
All 00_example_00.txt, 00_example_01.txt, 00_example_02.txt, 01_dense_00.txt, 02_path_00.txt, 02_path_01.txt, 02_path_02.txt, 02_path_03.txt, 02_path_04.txt, 02_path_05.txt, 02_path_06.txt, 02_path_07.txt, 02_path_08.txt, 02_path_09.txt, 03_paths_00.txt, 03_paths_01.txt, 03_paths_02.txt, 04_cycles_00.txt, 04_cycles_01.txt, 04_cycles_02.txt, 04_cycles_03.txt, 04_cycles_04.txt, 04_cycles_05.txt, 05_corner_00.txt, 05_corner_01.txt, 05_corner_02.txt, 05_corner_03.txt, 05_corner_04.txt, 05_corner_05.txt, 06_random_00.txt, 06_random_01.txt, 06_random_02.txt, 06_random_03.txt, 06_random_04.txt, 07_small_00.txt, 07_small_01.txt
ケース名 結果 実行時間 メモリ
00_example_00.txt AC 10 ms 8092 KiB
00_example_01.txt AC 9 ms 8080 KiB
00_example_02.txt AC 9 ms 8100 KiB
01_dense_00.txt AC 9 ms 8212 KiB
02_path_00.txt AC 66 ms 20536 KiB
02_path_01.txt AC 54 ms 19228 KiB
02_path_02.txt AC 24 ms 13088 KiB
02_path_03.txt AC 45 ms 17600 KiB
02_path_04.txt AC 31 ms 13308 KiB
02_path_05.txt AC 47 ms 17052 KiB
02_path_06.txt AC 26 ms 12120 KiB
02_path_07.txt AC 50 ms 18256 KiB
02_path_08.txt AC 23 ms 13320 KiB
02_path_09.txt AC 7 ms 8332 KiB
03_paths_00.txt AC 11 ms 8100 KiB
03_paths_01.txt AC 10 ms 8200 KiB
03_paths_02.txt AC 8 ms 8272 KiB
04_cycles_00.txt AC 8 ms 8196 KiB
04_cycles_01.txt AC 7 ms 8152 KiB
04_cycles_02.txt AC 11 ms 8092 KiB
04_cycles_03.txt AC 8 ms 8176 KiB
04_cycles_04.txt AC 7 ms 8172 KiB
04_cycles_05.txt AC 7 ms 8088 KiB
05_corner_00.txt AC 41 ms 15356 KiB
05_corner_01.txt AC 43 ms 15280 KiB
05_corner_02.txt AC 45 ms 14840 KiB
05_corner_03.txt AC 42 ms 14660 KiB
05_corner_04.txt AC 42 ms 14492 KiB
05_corner_05.txt AC 42 ms 14848 KiB
06_random_00.txt AC 8 ms 8216 KiB
06_random_01.txt AC 6 ms 8140 KiB
06_random_02.txt AC 6 ms 8272 KiB
06_random_03.txt AC 10 ms 8216 KiB
06_random_04.txt AC 10 ms 8200 KiB
07_small_00.txt AC 6 ms 8084 KiB
07_small_01.txt AC 11 ms 8096 KiB