Submission #371133


Source Code Expand

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

#define MAXV 100010

int parent[MAXV],rank[MAXV];

void init(int n){
	int i;
	REP(i,n) {parent[i] = i; rank[i] = 1;}
}

int root(int x){
	if(parent[x] != x) parent[x] = root(parent[x]);
	return parent[x];
}

void connect(int x, int y){
	int rx=root(x),ry=root(y);
	if(rx == ry) return;
	if(rank[rx] > rank[ry]) {parent[ry] = rx; rank[rx] += rank[ry];}
	if(rank[rx] <= rank[ry]) {parent[rx] = ry; rank[ry] += rank[rx];}
}

vector <int> graph[100010];
int dist[100010];

void dfs(int p, int x, int d){
	dist[x] = d;
	int i;
	REP(i,graph[x].size()){
		int y = graph[x][i];
		if(y != p) dfs(x, y, d+1);
	}
}

int main(void){
	int s=-1,t=-1,i,j,N;
	
	cin >> N;
	init(N);
	
	REP(i,N){
		int a,b;
		scanf("%d%d", &a, &b);
		a--; b--;
		
		if(root(a) == root(b)){
			s = a; t = b;
		} else {
			connect(a, b);
			graph[a].push_back(b);
			graph[b].push_back(a);
		}
	}
	
	dfs(-1, s, 0);
	
	int cycle = dist[t];
	cycle++;
	// cout << cycle << endl;
	
	int small = 1;
	if(cycle == N) small = 2;
	int big = N;
	if(cycle % 2 == 1) big--;
	cout << small << ' ' << big << endl;
	
	return 0;
}

Submission Info

Submission Time
Task C - 最小カットと最大カット
User cgyrngmoon
Language C++ (GCC 4.9.2)
Score 100
Code Size 1652 Byte
Status AC
Exec Time 166 ms
Memory 12528 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:66:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
                        ^

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 29
Set Name Test Cases
All scrambled_00.txt, scrambled_01.txt, scrambled_02.txt, scrambled_03.txt, scrambled_04.txt, scrambled_05.txt, scrambled_06.txt, scrambled_07.txt, scrambled_08.txt, scrambled_09.txt, scrambled_10.txt, scrambled_11.txt, scrambled_12.txt, scrambled_13.txt, scrambled_14.txt, scrambled_15.txt, scrambled_16.txt, scrambled_17.txt, scrambled_18.txt, scrambled_19.txt, scrambled_20.txt, scrambled_21.txt, scrambled_22.txt, scrambled_23.txt, scrambled_24.txt, scrambled_25.txt, scrambled_26.txt, scrambled_27.txt, scrambled_28.txt
Case Name Status Exec Time Memory
scrambled_00.txt AC 45 ms 3568 KB
scrambled_01.txt AC 40 ms 3504 KB
scrambled_02.txt AC 40 ms 3508 KB
scrambled_03.txt AC 162 ms 12528 KB
scrambled_04.txt AC 166 ms 12524 KB
scrambled_05.txt AC 105 ms 9072 KB
scrambled_06.txt AC 74 ms 7020 KB
scrambled_07.txt AC 153 ms 11884 KB
scrambled_08.txt AC 65 ms 6384 KB
scrambled_09.txt AC 76 ms 7276 KB
scrambled_10.txt AC 108 ms 8296 KB
scrambled_11.txt AC 60 ms 5352 KB
scrambled_12.txt AC 93 ms 7264 KB
scrambled_13.txt AC 86 ms 7012 KB
scrambled_14.txt AC 141 ms 7920 KB
scrambled_15.txt AC 103 ms 6644 KB
scrambled_16.txt AC 68 ms 5100 KB
scrambled_17.txt AC 65 ms 5292 KB
scrambled_18.txt AC 142 ms 7984 KB
scrambled_19.txt AC 44 ms 3948 KB
scrambled_20.txt AC 89 ms 6256 KB
scrambled_21.txt AC 66 ms 5224 KB
scrambled_22.txt AC 103 ms 6636 KB
scrambled_23.txt AC 72 ms 5424 KB
scrambled_24.txt AC 70 ms 5232 KB
scrambled_25.txt AC 78 ms 5752 KB
scrambled_26.txt AC 69 ms 5368 KB
scrambled_27.txt AC 92 ms 6256 KB
scrambled_28.txt AC 83 ms 5996 KB