답안 #666373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
666373 2022-11-28T10:42:35 Z Kaztaev_Alisher Hard route (IZhO17_road) C++17
19 / 100
12 ms 596 KB
//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")
 
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long  , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x  << " = " << x << endl;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;
 
const ll N = 2e3+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;
 
using namespace std;

int n , ok = 0 , cnt1 = 0 , cnt = 0 , kal = 0;
vector<int> g[N] , vec;
bool was[N];
void dfs(int v , int fn , int p){
	was[v] = 1;
	cnt++;
	if(v == fn){
		cnt1 = cnt;
		ok = 1;
		return;
	}
	for(int to : g[v]){
		if(to==p) continue;
		dfs(to , fn , v);
		if(ok == 1) return;
	}
	if(ok == 1) return;
	cnt--;
	was[v] = 0;
}
void get(int v ,int p){
	if(was[v] == 1){
		ok = 1;
		return;
	}
	kal++;
	for(int to : g[v]){
		if(to == p) continue;
		get(to,v);
		if(ok == 1) return;
	}
	kal--;
}
void solve(){
	cin >> n;
	for(int i = 1; i < n; i++){
		int a , b;
		cin >> a >> b;
		g[a].pb(b);
		g[b].pb(a);
	}
	for(int i = 1; i <= n; i++){
		if(g[i].sz() == 1) vec.pb(i);
	}
	int ans = 0 , ans2 = 0;
	for(int i = 0; i < vec.sz(); i++){		
		for(int j = i+1; j < vec.sz(); j++){
			int mx = 0;
			ok = 0;
			cnt = 0;
			cnt1 = 0;
			dfs(vec[i] , vec[j] , 0);
			for(int k = 0; k < vec.sz(); k++){
				if(i != k && j != k){
					kal = 0;
					ok = 0;
					get(vec[k] , 0);
					mx = max(mx , kal);
				}
			}
			for(int k = 1; k <= n; k++) was[k] = 0;
			cnt1--;
			if(cnt1*mx > ans){
				ans = cnt1*mx;
				ans2 = 1;
			} else if(cnt1*mx == ans) ans2++;
		}
	}	
	cout << ans <<" " << ans2 <<"\n";
}
signed main(){
	file("road");
	ios;
	solve();
	return 0;
}
/*
*/ 

Compilation message

road.cpp: In function 'void solve()':
road.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |  for(int i = 0; i < vec.sz(); i++){
      |                 ~~^~~~~~~~~~
road.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   for(int j = i+1; j < vec.sz(); j++){
      |                    ~~^~~~~~~~~~
road.cpp:89:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |    for(int k = 0; k < vec.sz(); k++){
      |                   ~~^~~~~~~~~~
road.cpp: In function 'int main()':
road.cpp:17:48: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
      |                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
road.cpp:108:2: note: in expansion of macro 'file'
  108 |  file("road");
      |  ^~~~
road.cpp:17:77: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
      |                                                                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
road.cpp:108:2: note: in expansion of macro 'file'
  108 |  file("road");
      |  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 372 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 11 ms 368 KB Output is correct
12 Correct 11 ms 376 KB Output is correct
13 Correct 12 ms 372 KB Output is correct
14 Correct 9 ms 340 KB Output is correct
15 Correct 1 ms 368 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 372 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 5 ms 372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 372 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 11 ms 368 KB Output is correct
12 Correct 11 ms 376 KB Output is correct
13 Correct 12 ms 372 KB Output is correct
14 Correct 9 ms 340 KB Output is correct
15 Correct 1 ms 368 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 372 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 5 ms 372 KB Output is correct
25 Runtime error 1 ms 596 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 372 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 11 ms 368 KB Output is correct
12 Correct 11 ms 376 KB Output is correct
13 Correct 12 ms 372 KB Output is correct
14 Correct 9 ms 340 KB Output is correct
15 Correct 1 ms 368 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 372 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 5 ms 372 KB Output is correct
25 Runtime error 1 ms 596 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -