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 15:14:33
Task:Data Packet Routing
Sender:Wave of Technology
Submission time:2018-05-26 15:14:33
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

const ll INF = 1000000000000000LL;

ll n;

template<typename T>
void print_vector(vector<T> & v) {
  for (auto x : v) {
    cout << x << " ";
  }
}

ll solve() {
  ll n, m;
  cin >> n >> m;
  set<PLL> s;
  ll res = 1;
  for (int i=0; i<m; i++) {
    ll a, b;
    cin >> a >> b;
    auto p = make_pair(a, b);
    if (s.count(p)) {
      res = 2;
    }
    s.insert(p);
  }

  return res;
}

int main() {

  cin.tie(NULL);
  std::ios::sync_with_stdio(false);

  ll t;
  cin >> t;
  for (int i=0; i<t; i++) {
    cout << solve() << endl;
  }
  
  return 0;
}