답안 #17956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
17956 2016-01-13T09:39:13 Z Adilkhan 관광지 (IZhO14_shymbulak) C++
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

#define pb push_back
#define endl "\n"
#define mp make_pair 
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fname ""
#define sz(x) (int)(x.size())
#define int long long

typedef long long ll;

using namespace std;

const ll N = (ll)(5e5) + 322;
const ll INF = (ll)(1e9);
const ll mod = (ll)(1e9) + 7;
const double eps = 1e-9;

int d[N][2], n, m, mx, sum;
        
vector <int> v[N];

queue <int> q;

void fmbfs(int s) {
	memset(d, -1, sizeof d);
	for (int i = 1; i <= n; ++i) d[i][1] = 0;
	q.push(s);
	d[s][0] = 0; d[s][1] = 1;
	while (!q.empty()) {
		int x = q.front();
		q.pop();
		for (auto to : v[x]) {
			if (d[to][0] == -1) {
				d[to][0] = d[x][0] + 1;
				d[to][1] += d[x][1];
				q.push(to);			
				continue;
			}		
			if (d[to][0] == d[x][0] + 1) {
				d[to][1] += d[x][1];
			}
		}	
	}	
	for (int i = 1; i <= n; ++i) {
		mx = max(mx, d[i][0]);
	}         
}

bool bfs(int s) {
	int z = sum;
	memset(d, -1, sizeof d);
	for (int i = 1; i <= n; ++i) d[i][1] = 0;
	q.push(s);
	d[s][0] = 0; d[s][1] = 1;
	while (!q.empty()) {
		int x = q.front();
		q.pop();
		for (auto to : v[x]) {
			if (d[to][0] == -1) {
				d[to][0] = d[x][0] + 1;
				d[to][1] += d[x][1];
				q.push(to);			
				continue;
			}		
			if (d[to][0] == d[x][0] + 1) {
				d[to][1] += d[x][1];
			}
		}	
	}	
	for (int i = 1; i <= n; ++i) {
		if (mx == d[i][0]) {
			sum += d[i][1];
		}
	}
	return (z == sum);
}

main () {
//	freopen(fname".in", "r", stdin);
	//freopen(fname".out", "w", stdout);
	scanf("%lld", &n);
	for (int i = 1; i <= n; ++i) {
		int x, y; scanf("%lld%lld", &x, &y);
		v[x].pb(y); v[y].pb(x);
	}
	for (int i = 1; i <= n; ++i) {
		fmbfs(i);
	}
	for (int i = 1; i <= n; ++i) {
		if (!bfs(i)) {
			v[i].clear();			
		}      
	}
	printf("%lld", sum / 2);
	return 0;
}

Compilation message

shymbulak.cpp: In function ‘void fmbfs(long long int)’:
shymbulak.cpp:36:8: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
   for (auto to : v[x]) {
        ^
shymbulak.cpp:36:13: error: ‘to’ does not name a type
   for (auto to : v[x]) {
             ^
shymbulak.cpp:47:2: error: expected ‘;’ before ‘}’ token
  } 
  ^
shymbulak.cpp:47:2: error: expected primary-expression before ‘}’ token
shymbulak.cpp:47:2: error: expected ‘;’ before ‘}’ token
shymbulak.cpp:47:2: error: expected primary-expression before ‘}’ token
shymbulak.cpp:47:2: error: expected ‘)’ before ‘}’ token
shymbulak.cpp:47:2: error: expected primary-expression before ‘}’ token
shymbulak.cpp:34:7: warning: unused variable ‘x’ [-Wunused-variable]
   int x = q.front();
       ^
shymbulak.cpp: In function ‘bool bfs(long long int)’:
shymbulak.cpp:62:8: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
   for (auto to : v[x]) {
        ^
shymbulak.cpp:62:13: error: ‘to’ does not name a type
   for (auto to : v[x]) {
             ^
shymbulak.cpp:73:2: error: expected ‘;’ before ‘}’ token
  } 
  ^
shymbulak.cpp:73:2: error: expected primary-expression before ‘}’ token
shymbulak.cpp:73:2: error: expected ‘;’ before ‘}’ token
shymbulak.cpp:73:2: error: expected primary-expression before ‘}’ token
shymbulak.cpp:73:2: error: expected ‘)’ before ‘}’ token
shymbulak.cpp:73:2: error: expected primary-expression before ‘}’ token
shymbulak.cpp:60:7: warning: unused variable ‘x’ [-Wunused-variable]
   int x = q.front();
       ^
shymbulak.cpp: At global scope:
shymbulak.cpp:82:7: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
 main () {
       ^
shymbulak.cpp: In function ‘int main()’:
shymbulak.cpp:85:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
                   ^
shymbulak.cpp:87:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%lld%lld", &x, &y);
                                      ^