답안 #344661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
344661 2021-01-06T07:18:34 Z mansur 관광지 (IZhO14_shymbulak) C++14
0 / 100
46 ms 5224 KB
#include<bits/stdc++.h>
using namespace std;

#define all(a) a.begin(),a.end()
#define ll long long
#define pb push_back
#define nl '\n'
#define popb pop_back()
#define sz size()
#define ld long double
#define ull unsigned long long
#define F first
#define S second
#define fix fixed<<setprecision
#define pii pair<int,int>
#define E exit (0)
#define int long long
const int inf=1e9;
int c[501][501],cnt;
vector<pii>adj[501];
map<int,bool>was;
void dfs(int u,int z,int mx,int t=0) {
	was[u]=1;
	if (t>mx) {
		was[u]=0;
		return;
	}
	if (u==z) {
		cnt++;
		was[u]=0;
		return;
	}
	for (auto e:adj[u]) {
		if (was[e.F]) {
			continue;
		}
		dfs(e.F,z,mx,t+1);
	}
	was[u]=0;
	return;
}
signed main() {
	//freopen("planting.in","r",stdin);
	//freopen("planting.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	for (int i=1;i<=n;i++) {
	 	for (int j=1;j<=n;j++) {
	 		c[i][j]=inf;	
		}
	}
	for (int i=1;i<=n;i++) {
		c[i][i]=0;
		int a,b;
		cin>>a>>b;
		c[a][b]=c[b][a]=1;
		adj[a].pb({b,i});
		adj[b].pb({a,i});
	}
	for (int k=1;k<=n;k++) {
		for (int i=1;i<=n;i++) {
			for (int j=1;j<=n;j++) {
				c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
			}	
		}
	}
	int mx=0;
	vector<pii>s;
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=n;j++) {
			if (mx==c[i][j]) {
				s.pb({i,j});
			}
			if (mx<c[i][j]) {
				mx=c[i][j];
				s.clear();
				s.pb({i,j});
			}
		}
	}       
	int ans=0,i=0;
	for (auto e:s) {
		if (i==s.sz/2) {
			break;
		}
		dfs(e.F,e.S,mx);
		ans+=cnt;
		for (int i=1;i<=500;i++) {
			was[i]=0;
        }
        cnt=0;
        i++;
	}
	cout<<ans;
}                                  	
                                	

Compilation message

shymbulak.cpp: In function 'int main()':
shymbulak.cpp:85:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   if (i==s.sz/2) {
      |       ~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Incorrect 1 ms 492 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 4972 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 5224 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -