Code Submission Evaluation System Login

CSES - HIIT Open 2018

HIIT Open 2018

Contest start:2018-05-26 11:00:00
Contest end:2018-05-26 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2018-05-26 12:49:23
2018-05-26 12:46:57
Task:Data Packet Routing
Sender:Karhukopla
Submission time:2018-05-26 12:49:23
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

#define ll long long
#define lll __int128
#define pii pair<int, int>
#define M 1000000007
#define N 101
#define push_back PB
#define F first
#define S second
using namespace std;

int v[1001][1001];

int solve() {
	int n, m;
	cin>>n>>m;
	int ans = 1;
	vector<pii> q(m);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin>>a>>b;
		if (v[a][b]) {
			ans = 2;
		}
		v[a][b] = 1;
		q[i] = {a, b};
	}
	for (pii p : q) {
		v[p.F][p.S] = 0;
	}
	return ans;
}

int main () {
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll t; cin >> t;
	while(t--) cout<<solve()<<endl;
}