【编程题目 |100分】We Are A Team【2021, 2022 H1 考试题 2023 Q2考试题 B卷】


时间限制:C/C++ 1秒,其他语言 2秒

空间限制:C/C++262144K,其他语言524288K

64bit IO Format:%lld


本题可使用本地IDE编码,不能使用本地已有代码,无跳出限制,

编码后请点击”保存并调试“按钮进行代码提交。


题目描述

【We Are A Team】

总共有 n 个人在机房,每个人有一个标号(1<=标号<=n),他们分成了多个团队,需要你根据收到的 m 条消息判定指定的两个人是否在一个团队中,具体的:

1、消息构成为 a b c,整数 a、b 分别代表两个人的标号,整数 c 代表指令

2、c == 0 代表 a 和 b 在一个团队内

3、c == 1 代表需要判定 a 和 b 的关系,如果 a 和 b 是一个团队,输出一行’we are a team’,如果不是,输出一行’we are not a team’

4、c 为其他值,或当前行 a 或 b 超出 1~n 的范围,输出‘da pian zi’

输入描述

  1. 第一行包含两个整数 n,m(1<=n,m<100000),分别表示有 n 个人和 m 条消息
  2. 随后的 m 行,每行一条消息,消息格式为:a b c(1<=a,b<=n,0<=c<=1)
  3. 输出描述: 1、c ==1,根据 a 和 b 是否在一个团队中输出一行字符串,在一个团队中输出‘we are a team‘,不在一个团队中输出’we are not a team’ 2、c 为其他值,或当前行 a 或 b 的标号小于 1 或者大于 n 时,输出字符串‘da pian zi
  4. 如果第一行 n 和 m 的值超出约定的范围时,输出字符串”Null“。

示例1 输入输出示例仅供调试,后台判题数据一般不包含示例

输入

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
5 7
1 2 0
4 5 0
2 3 0
1 2 1
2 3 1
4 5 1
1 5 1
5 7 1 2 0 4 5 0 2 3 0 1 2 1 2 3 1 4 5 1 1 5 1
5 7

1 2 0

4 5 0

2 3 0

1 2 1

2 3 1

4 5 1

1 5 1

输出

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
We are a team
We are a team
We are a team
We are not a team
We are a team We are a team We are a team We are not a team
We are a team

We are a team

We are a team

We are not a team

示例2 输入输出示例仅供调试,后台判题数据一般不包含示例

输入

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
5 6
1 2 0
1 2 1
1 5 0
2 3 1
2 5 1
1 3 2
5 6 1 2 0 1 2 1 1 5 0 2 3 1 2 5 1 1 3 2
5 6

1 2 0

1 2 1

1 5 0

2 3 1

2 5 1

1 3 2

输出

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
we are a team
we are not a team
we are a team
da pian zi
we are a team we are not a team we are a team da pian zi
we are a team

we are not a team

we are a team

da pian zi

C++解法一


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N = 1e5 + 10;
int n,m;
vector<int> fa;
void init(int len){
fa.resize(len);
for(int i = 0; i < len; i++){
fa[i] = i;
}
}
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; const int N = 1e5 + 10; int n,m; vector<int> fa; void init(int len){ fa.resize(len); for(int i = 0; i < len; i++){ fa[i] = i; } }
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
const int N = 1e5 + 10;
int n,m;
vector<int> fa;

void init(int len){
    fa.resize(len);
    for(int i = 0; i < len; i++){
        fa[i] = i;
    }
}

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

C++解法二


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h> using namespace std;
#include<bits/stdc++.h>

using namespace std;

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

JAVA 解法一


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

JAVA 解法二


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] nms = sc.nextLine().split(" ");
int nums = Integer.parseInt(nms[0]);
int mes = Integer.parseInt(nms[1]);
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] nms = sc.nextLine().split(" "); int nums = Integer.parseInt(nms[0]); int mes = Integer.parseInt(nms[1]);
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] nms = sc.nextLine().split(" ");
        int nums = Integer.parseInt(nms[0]);
        int mes = Integer.parseInt(nms[1]);

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

Python


剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看

JavaScript


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
let s = readLine().split(" ").map(Number);
let n = s[0];
let m = s[1];
let s = readLine().split(" ").map(Number); let n = s[0]; let m = s[1];
let s = readLine().split(" ").map(Number);
 
let n = s[0];
let m = s[1];

剩余50%内容,购买单篇文章或订阅会员后查看


隐藏内容

此处内容需要权限查看

  • 普通用户特权:11金币
  • 会员用户特权:免费
  • 永久会员用户特权:免费推荐
会员免费查看