Submission #20083

# Submission time Handle Problem Language Result Execution time Memory
20083 2016-02-25T10:45:54 Z hongjun7 트리 (kriii4_X) C++
Compilation error
0 ms 0 KB
#include <stdio.h>
#include <map>
using namespace std;
const int mod = 1e9+7;
int N, M;
map<int, int> par, cnt;
int F(int x) {
	if (!par.count(x)) par[x] = x;
	if (par[x] == x) return x;
	return (par[x] = F(par[x]));
}
int mul(int x, int y) { return (long long)x * y % mod; }
int fm(int x, int y) {
	if (y == 0) return 1;
	int r = fm(x, y / 2);
	r = mul(r, r);
	if (y % 2 == 1) r = mul(r, x);
	return r;
}
int main() {
	scanf("%d%d", &N, &M);
	bool ok = 1;
	for (int i = 1; i <= M; i++) {
		int x, y; scanf("%d%d", &x, &y);
		int px = F(x), py = F(y);
		if (px == py) ok = 0;
		else par[px] = py;
	}
	int res = 0;
	if (ok) {
		for (auto x : par) cnt[F(x.first)]++;
		res = fm(N, N - par.size() + cnt.size() - 2);
		if (res < 1) res = 1;
		for (auto x : cnt) res = mul(res, x.second);
	}
	printf("%d", res);
}

Compilation message

X.cpp: In function ‘int main()’:
X.cpp:31:8: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
   for (auto x : par) cnt[F(x.first)]++;
        ^
X.cpp:31:13: error: ‘x’ does not name a type
   for (auto x : par) cnt[F(x.first)]++;
             ^
X.cpp:32:3: error: expected ‘;’ before ‘res’
   res = fm(N, N - par.size() + cnt.size() - 2);
   ^
X.cpp:32:46: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   res = fm(N, N - par.size() + cnt.size() - 2);
                                              ^
X.cpp:33:3: error: expected primary-expression before ‘if’
   if (res < 1) res = 1;
   ^
X.cpp:33:3: error: expected ‘)’ before ‘if’
X.cpp:34:8: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
   for (auto x : cnt) res = mul(res, x.second);
        ^
X.cpp:34:13: error: ‘x’ does not name a type
   for (auto x : cnt) res = mul(res, x.second);
             ^
X.cpp:35:2: error: expected ‘;’ before ‘}’ token
  }
  ^
X.cpp:35:2: error: expected primary-expression before ‘}’ token
X.cpp:35:2: error: expected ‘;’ before ‘}’ token
X.cpp:35:2: error: expected primary-expression before ‘}’ token
X.cpp:35:2: error: expected ‘)’ before ‘}’ token
X.cpp:35:2: error: expected primary-expression before ‘}’ token
X.cpp:21:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
                       ^
X.cpp:24:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d", &x, &y);
                                  ^