Submission #2337431


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct UnionFind
{
  vector< int > data;
  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }
  int find(int k)
  {
    if(data[k] < 0) return(k);
    return(data[k] = find(data[k]));
  }
  void unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x != y) {
      if(data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }
};   
int main()
{
  int N, M, power[100001];
  power[0] = 1;
  for(int i = 1; i < 100001; i++) {
    power[i] = 1LL * power[i - 1] * 2 % mod;
  }
  while(scanf("%d %d", &N, &M), N) {
    UnionFind tree(N);
    for(int i = 0; i < M; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      tree.unite(--x, --y);
    }
    int group = 0;
    for(int i = 0; i < N; i++) {
      group += tree.find(i) == i;
    }
    printf("%d\n", power[group] + (group != N));
  }
}

Submission Info

Submission Time
Task D - Everlasting -One-
User ei13333
Language C++14 (GCC 5.4.1)
Score 100
Code Size 943 Byte
Status AC
Exec Time 82 ms
Memory 1024 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:33:3: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   while(scanf("%d %d", &N, &M), N) {
   ^
./Main.cpp:37:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d", &x, &y);
                             ^

Judge Result

Set Name all
Score / Max Score 100 / 100
Status
AC × 1
Set Name Test Cases
all Merged
Case Name Status Exec Time Memory
Merged AC 82 ms 1024 KB