MIDOU_A @ 2025-01-11 00:01:22
P5651 基础最短路练习题40求调
#include <bits/stdc++.h>
#define ll long long
#define c1 cout << 1 << " "
#define cen cout << endl
using namespace std;
void f(){
}
vector<pair<int,int> > v[100009];
long long dis[100009]={0};
bool vis[100009]={0};
void dfs(int i,long long sum){
dis[i]=sum;
for(int j=0;j<v[i].size();j++){
if(!vis[j]){
vis[j]=1;
dfs(v[i][j].first,(i==0?v[i][j].second:sum^v[i][j].second));
vis[j]=0;
}
}
}
int main(){
int n,m,q;
cin >> n >> m >> q;
int x,y,u;
for(int i=0;i<m;i++){
cin >> x >> y >> u;
x--;y--;
v[x].push_back({y,u});
v[y].push_back({x,u});
}
dfs(0,0);
while(q--){
cin >> x >> y;
x--;y--;
cout << (dis[x]^dis[y]) << endl;
}
return 0;
}
by lyb_qhd @ 2025-01-11 09:53:10
整理一下马蜂
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<pair<int, int> > v[100009];
long long dis[100009] = {0};
bool vis[100009] = {0};
void dfs( int i, long long sum ) {
dis[i] = sum;
for( int j = 0; j < v[i].size(); j++ ) {
if( !vis[j] ) {
vis[j] = 1;
dfs( v[i][j].first, ( i == 0 ? v[i][j].second : sum ^ v[i][j].second ) );
vis[j] = 0;
}
}
}
int main() {
int n, m, q;
cin >> n >> m >> q;
int x, y, u;
for( int i = 0; i < m; i++ ) {
cin >> x >> y >> u;
x--;
y--;
v[x].push_back( {y, u} );
v[y].push_back( {x, u} );
}
dfs( 0, 0 );
while( q-- ) {
cin >> x >> y;
x--;
y--;
cout << ( dis[x]^dis[y] ) << endl;
}
return 0;
}
没调