-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoj2001.cpp
More file actions
51 lines (50 loc) · 1.08 KB
/
aoj2001.cpp
File metadata and controls
51 lines (50 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;
int main() {
int n, m, a;
while(cin >> n >> m >> a, n|m|a) {
vector<pair<int, pair<int, int> > > ppi;
REP(i, m) {
int in[3];
REP(j, 3) cin >> in[j];
ppi.push_back(make_pair(in[0], make_pair(in[1], in[2])));
sort(ppi.begin(), ppi.end());
reverse(ppi.begin(), ppi.end());
}
int ans = a;
int now = INF;
REP(i, ppi.size()) {
if(ppi[i].first == now) continue;
if(ppi[i].second.first == ans) {
ans = ppi[i].second.second;
now = ppi[i].first;
}
else if(ppi[i].second.second == ans) {
ans = ppi[i].second.first;
now = ppi[i].first;
}
}
cout << ans << endl;
}
return 0;
}