NKOJ P4252数三角形

来源:互联网 发布:ubuntu下搭建samba 编辑:程序博客网 时间:2024/05/11 18:51

P4252数三角形
时间限制 : - MS 空间限制 : 265536 KB
评测说明 : 1s
问题描述

刚刚上高中的洁洁在学习组合数学的过程中遇到一道麻烦的题目,她希望你能帮助她解决。给定一张无向完全图 G,其中大部分边被染成蓝色,但也有一些边被染成红色或者绿色。现在,洁洁需要给这张图的多样性进行打分。一张图的多样性取决于它的同色和异色三角形的个数。具体来说,G 中每有一个三边颜色都互不同的三角形(异色三角形)可以得 3 分,每有一个三边颜色都相同的三角形(同色三角形)则要被扣掉 6 分,其它三角形不得分也不扣分。

现在,请你写一个程序来计算 G 的多样性分数。

输入格式

第一行两个正整数 n 和 m,其中 n 表示 G 中顶点的个数,m表示 G 中红色或者绿色的边的条数。

接下来 m行每行包括三个整数 a,b,c代表连接顶点 a和顶点 b的边颜色为红色 (c=1)或者绿色 (c=2)。

输出格式

一行G的多样性得分。

样例输入 1

4 3
1 2 1
1 3 1
2 3 1

样例输出 1

-6

样例输入 2

4 4
1 2 1
1 3 1
2 3 1
1 4 2

样例输出 2

0

提示

对于 20%20\%20% 的数据,n≤500,m≤n(n−1)/2。

对于 40%40\%40% 的数据,n≤2000,m≤n(n−1)/2。

对于 100%100\%100% 的数据,n≤100000,m≤min(n(n−1)/2,200000)。
样例解释 1

(1,2,3)能组成一个同色三角形,找不到异色三角形,得分为 −6。
样例解释 2

(1,2,3) 能组成一个同色三角形,(1,2,4),(1,3,4) 能组成两个异色三角形,得分为 2∗3−6=0
样例输入1

4 3
1 2 1
1 3 1
2 3 1

题很简单,找找规律而已,可是蒟蒻我在考试时一个多小时没推出来。我发这个博客不是为了发题解的。而是……

发个很(丑)好(陋)的代码的。

#include<stdio.h>#define satisfied_and_drive_your_computer_too_hard while#define one_case if#define the_other_case else#define you_really_want_to_exist_right___ return#define a_type_which_return_nothing void#define a_integer_type_which_needs_32_bit int#define please_do_not_drive_your_computer_to_hard for#define let_the_computer_get_a_character getchar#define I_donot_wanna_you_to_open_my_file freopen#define a_integer_type_which_needs_64_bit long long #define mercilessly_and_unrelantingly_put_a_character putchar#define we_wanna_some_space_to_store_data 100001a_integer_type_which_needs_64_bit read_an_long_long_interger_which_satisfy_the_problem(){    a_integer_type_which_needs_64_bit the_result_must_be_right___=0,let_me_see_whether_the_number_is_minus=1;char character=let_the_computer_get_a_character();    satisfied_and_drive_your_computer_too_hard(character>'9'||character<'0'){one_case(character=='-')let_me_see_whether_the_number_is_minus=-let_me_see_whether_the_number_is_minus;character=let_the_computer_get_a_character();}      satisfied_and_drive_your_computer_too_hard(character>='0'&&character<='9'){the_result_must_be_right___=(the_result_must_be_right___<<3)+(the_result_must_be_right___<<1)+character-'0';character=let_the_computer_get_a_character();}      you_really_want_to_exist_right___ the_result_must_be_right___*let_me_see_whether_the_number_is_minus;}a_type_which_return_nothing I_am_not_sure_whether_the_answer_is_true_or_false(a_integer_type_which_needs_64_bit the_number_which_should_be_written){    one_case(the_number_which_should_be_written<0)the_number_which_should_be_written=-the_number_which_should_be_written,mercilessly_and_unrelantingly_put_a_character('-');    one_case(the_number_which_should_be_written>9)I_am_not_sure_whether_the_answer_is_true_or_false(the_number_which_should_be_written/10);    mercilessly_and_unrelantingly_put_a_character(the_number_which_should_be_written%10+48);}a_integer_type_which_needs_64_bit how_many_red_edge_link_to_this_node[we_wanna_some_space_to_store_data],how_many_green_edge_link_to_this_node[we_wanna_some_space_to_store_data],how_many_blue_edge_link_to_this_node[we_wanna_some_space_to_store_data],the_lovely_ans;//how_many_red_edge_link_to_this_node[shadow_iterator] refers to how many red edge link to shadow_iterator node.a_integer_type_which_needs_64_bit red_edge_and_green_edge,red_edge_and_blue_edge,green_edge_and_blue_edge,red_edge_and_red_edge,green_edge_and_green_edge,blue_edge_and_blue_edge;a_integer_type_which_needs_64_bit let_us_get_this_point_s_combination(a_integer_type_which_needs_64_bit current_number){    you_really_want_to_exist_right___ (current_number*(current_number-1))>>1;}a_type_which_return_nothing do_you_know_the_answer_is_true_or_false_however_I_think_it_is_true(){    the_lovely_ans=(red_edge_and_green_edge+red_edge_and_blue_edge+green_edge_and_blue_edge)-(red_edge_and_red_edge+blue_edge_and_blue_edge+green_edge_and_green_edge<<1);    I_am_not_sure_whether_the_answer_is_true_or_false(the_lovely_ans);}a_integer_type_which_needs_32_bit main(){     //I_donot_wanna_you_to_open_my_file("count.in","r",stdin);    //I_donot_wanna_you_to_open_my_file("count.out","w",stdout);    a_integer_type_which_needs_64_bit n=read_an_long_long_interger_which_satisfy_the_problem(),m=read_an_long_long_interger_which_satisfy_the_problem(),shadow_iterator;    please_do_not_drive_your_computer_to_hard(shadow_iterator=1;shadow_iterator<=m;shadow_iterator=shadow_iterator+1){        a_integer_type_which_needs_64_bit a=read_an_long_long_interger_which_satisfy_the_problem(),b=read_an_long_long_interger_which_satisfy_the_problem(),c=read_an_long_long_interger_which_satisfy_the_problem();        one_case(c==1)how_many_red_edge_link_to_this_node[a]=how_many_red_edge_link_to_this_node[a]+1,how_many_red_edge_link_to_this_node[b]=how_many_red_edge_link_to_this_node[b]+1;        the_other_case how_many_green_edge_link_to_this_node[a]=how_many_green_edge_link_to_this_node[a]+1,how_many_green_edge_link_to_this_node[b]=how_many_green_edge_link_to_this_node[b]+1;    }    please_do_not_drive_your_computer_to_hard(shadow_iterator=1;shadow_iterator<=n;shadow_iterator=shadow_iterator+1){        how_many_blue_edge_link_to_this_node[shadow_iterator]=n-1-how_many_red_edge_link_to_this_node[shadow_iterator]-how_many_green_edge_link_to_this_node[shadow_iterator];        red_edge_and_green_edge=red_edge_and_green_edge+how_many_red_edge_link_to_this_node[shadow_iterator]*how_many_green_edge_link_to_this_node[shadow_iterator];        red_edge_and_blue_edge=red_edge_and_blue_edge+how_many_red_edge_link_to_this_node[shadow_iterator]*how_many_blue_edge_link_to_this_node[shadow_iterator];        green_edge_and_blue_edge=green_edge_and_blue_edge+how_many_green_edge_link_to_this_node[shadow_iterator]*how_many_blue_edge_link_to_this_node[shadow_iterator];        red_edge_and_red_edge=red_edge_and_red_edge+let_us_get_this_point_s_combination(how_many_red_edge_link_to_this_node[shadow_iterator]);        green_edge_and_green_edge=green_edge_and_green_edge+let_us_get_this_point_s_combination(how_many_green_edge_link_to_this_node[shadow_iterator]);        blue_edge_and_blue_edge=blue_edge_and_blue_edge+let_us_get_this_point_s_combination(how_many_blue_edge_link_to_this_node[shadow_iterator]);    }    do_you_know_the_answer_is_true_or_false_however_I_think_it_is_true();    you_really_want_to_exist_right___ 0;}
原创粉丝点击