比赛 2025.3.18 评测结果 AAAAAAAAAA
题目名称 奇偶性游戏 最终得分 100
用户昵称 健康铀 运行时间 0.067 s
代码语言 C++ 内存使用 3.44 MiB
提交时间 2025-03-18 18:58:56
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;

struct Condition { int u, v, t; } a[200001];
int f[400002], n, m;

int zuxian(int k) { return f[k] == k ? k : f[k] = zuxian(f[k]); }

int main() {
	freopen("parity.in","r",stdin);
	freopen("parity.out","w",stdout);
    cin >> n >> m;
    vector<int> b;
    
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> a[i].u >> a[i].v >> s;
        a[i].u--;
        a[i].t = (s[0] == 'o');
        b.push_back(a[i].u);
        b.push_back(a[i].v);
    }
    
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    int l = b.size();
    
    iota(f, f + 2 * l + 1, 0);
    
    for (int i = 0; i < m; ++i) {
        int u = lower_bound(b.begin(), b.end(), a[i].u) - b.begin() + 1;
        int v = lower_bound(b.begin(), b.end(), a[i].v) - b.begin() + 1;
        int t = a[i].t;
        int cond = v + (1 - t) * l;
        
        if (zuxian(u) == zuxian(cond)) {
            cout << i;
            return 0;
        }
        f[zuxian(u)] = zuxian(v + t * l);
        f[zuxian(u + l)] = zuxian(v + (1 - t) * l);
    }
    
    cout << m;
}